MobileBlur

Check-in [cbc0649388]
Login

Check-in [cbc0649388]

Overview
Comment:Moved newsblur library from urllib to Requests. Moved username storage to the DB. Store cookie in the DB. Centralize a login function that checks the DB for a user's cookie on each page load and logs the user in if there's no cookie.
Timelines: family | ancestors | descendants | both | develop
Files: files | file ages | folders
SHA1: cbc064938826076f057efd9ce59a865c90ff79c2
User & Date: spiffy on 2011-11-20 03:03:33
Other Links: branch diff | manifest | tags
Context
2011-11-20
03:12
Added a button to mark a feed as read check-in: b74e6c434b user: spiffy tags: develop
03:03
Moved newsblur library from urllib to Requests. Moved username storage to the DB. Store cookie in the DB. Centralize a login function that checks the DB for a user's cookie on each page load and logs the user in if there's no cookie. check-in: cbc0649388 user: spiffy tags: develop
2011-08-15
01:53
Mobileblur can log in for a user and get all feeds with unread content above a hardcoded threshold check-in: 6548f791b4 user: spiffy tags: develop
Changes

Modified applications/mobileblur/controllers/default.py from [2721664ca4] to [f7fe7a35c9].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27



1
2







3

4
5
6
7
8
9
10
11
12
13



-
-
-


-
-
-
-
-
-
-

-










-
-
-
# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations

from pprint import pprint

newsblur = local_import("newsblur")

username = ""
password = ""
threshold = 0
thresholds = ["nt", "ps", "ng"]  # indices -1, 0, 1 for negative, neutral, ane positive inhelligence filters

def index():
    newsblur.login(username, password)
    raw_feeds = newsblur.feeds(flat=True)["feeds"]
    feeds = {}
    for feed in raw_feeds.itervalues():
        for i in range(threshold, 2):
            if feed[thresholds[i]] > 0:
                feeds[feed["feed_title"]] = feed
                break

    pprint(feeds)
    return dict(feeds=feeds, threshold=threshold)
    
def login():
    pass

Modified applications/mobileblur/controllers/feeds.py from [ae6b12dd5f] to [61898c0aad].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15



1

2
3
4







5
6


7
8
9

-



-
-
-
-
-
-
-

+
-
-
+
+
+
# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations

from pprint import pprint

newsblur = local_import("newsblur")

username = ""
password = ""
threshold = 0
thresholds = ["nt", "ps", "ng"]  # indices -1, 0, 1 for negative, neutral, ane positive inhelligence filters

def view():
    stories = newsblur.feed(request.args[0])["stories"]
    newsblur.login(username, password)
    return 
    feeds = newsblur.feeds(flat=True)["feeds"]
    feed = [feed for feed in feeds.itervalues() if feed["id"]==int(request.args[0])][0]
    return dict(stories=stories, feed=feed)

Added applications/mobileblur/controllers/stories.py version [59984e848a].









1
2
3
4
5
6
7
8
+
+
+
+
+
+
+
+
# -*- coding: utf-8 -*-

from pprint import pprint

def view():
    stories = newsblur.feed(request.vars["feed_id"])["stories"]
    story = [story for story in stories if story["id"]==request.vars["story"]][0]
    return dict(story=story)

Added applications/mobileblur/models/0_helpers.py version [d9e34b5918].










1
2
3
4
5
6
7
8
9
+
+
+
+
+
+
+
+
+
newsblur = local_import("newsblur")

threshold = 0
thresholds = ["nt", "ps", "ng"]  # indices -1, 0, 1 for negative, neutral, and positive intelligence filters

def login(username="spiffytech"):
    user = db(db.users.username==username).select().first()
    if user["cookie"] is None:
        results = newsblur.login(user["username"], user["password"])

Modified applications/mobileblur/models/db.py from [f6575d3cb8] to [9c80a3439c].

1
2

3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10


+







# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations
from gluon.custom_import import track_changes; track_changes(True)

#########################################################################
## This scaffolding model makes your app work on Google App Engine too
#########################################################################

if request.env.web2py_runtime_gae:            # if running on Google App Engine
    db = DAL('google:datastore')              # connect to Google BigTable
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+







plugins = PluginManager()                      # for configuring plugins

mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = 'you@gmail.com'         # your email
mail.settings.login = 'username:password'      # your credentials or None

auth.settings.hmac_key = '<your secret key>'   # before define_tables()
auth.define_tables()                           # creates all needed tables
auth.define_tables(username=True)                           # creates all needed tables
auth.settings.mailer = mail                    # for user email verification
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = 'Click on the link http://'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s to reset your password'

75
76
77
78
79
80
81







76
77
78
79
80
81
82
83
84
85
86
87
88
89







+
+
+
+
+
+
+
##
## More API examples for controllers:
##
## >>> db.mytable.insert(myfield='value')
## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
## >>> for row in rows: print row.id, row.myfield
#########################################################################

db.define_table("users",
    Field("username"),
    Field("password"),
    Field("cookie")
)
login()

Modified applications/mobileblur/modules/newsblur.py from [9e60ae12cf] to [8c37485973].

1
2
3
4
5
6
7
8


9
10
11
12
13

14
15

16
17
18
19
20


21
22
23
24
25
26
27
28
29

30
31
32
33




34
35
36
37
38
39
40

41
42
43


44
45
46
47
48
49
50
51

52
53
54
55



56
57
58
59
60
61
62
63
64

65
66
67
68




69
70
71
72
73
74

75
76

77
78
79

80
81
82


83
84
85
86
87
88
89
90
91
92

93
94
95
96




97
98
99
100
101
102
103

104
105
106




107
108
109
110
111
112

113
114

115
116
117
118


119
120
121
122
123
124


125
126

127
128
129
130
131




132
133
134
135
136
137

138
139

140
141
142
143


144
145
146
147
148
149
150


151
152


153
154
155
156



157
158

159
160
161
162
163

164
165
166



167
168
169
170
171
172
173

174
175
176
177




178
179
180
181
182
183

184
185

186
187
188
189
190




191
192
193
194
195
196
197



198
199

200
201
202
203
204



205
206
207
208
209
210
211

212
213
214
215



216
217
218
219
220
221
222

223
224
225
226



227
228
229
230
231
232
233
234

235
236
237
238



239
240
241
242
243
244
245
246
247
248
249
250
251



252
253
254
255
256
257
258

259
260
261
262



263
264
265
266
267
268

269
270


271
272
273
274



275
276
277
278
279
280
281

282
283
284
285



286
287
288
289
290
291
292

293
294
295
296



297
298
299
300
301
302
303
304

305
306
307
308



309
310
311
312
313
314
315

316
317

318
319
320
321
322



323
324
325
326
327
328
329
330



331
332

333
334
335
336


337
338
339
340
341
342
343
344


345
346

347
348
349
350
351



352
353
354
355
356
357
358

359
360


361
362
363


364
365
366
367
368
369
370
371
372

373
374
375

376
377
378


1
2
3
4

5


6
7
8
9
10
11

12


13


14


15
16
17
18
19

20
21
22

23
24
25



26
27
28
29
30
31
32

33

34
35
36


37
38
39
40
41

42
43

44
45
46



47
48
49
50
51
52
53
54
55
56
57
58
59




60
61
62
63
64
65
66

67

68


69
70
71

72



73
74
75
76
77
78

79
80
81

82
83




84
85
86
87
88
89
90

91

92
93



94
95
96
97
98
99
100

101

102


103
104
105


106
107
108
109
110



111
112


113
114




115
116
117
118
119
120
121

122

123


124
125
126


127
128
129
130
131

132


133
134


135
136
137



138
139
140
141

142
143

144

145
146



147
148
149
150
151
152

153

154
155




156
157
158
159
160
161
162

163

164


165
166




167
168
169
170
171
172
173




174
175
176


177
178
179



180
181
182
183
184
185

186

187
188
189



190
191
192
193
194
195

196

197
198
199



200
201
202
203
204
205

206
207

208
209
210



211
212
213
214
215
216
217

218

219
220
221



222
223
224
225
226
227

228

229
230
231



232
233
234
235
236
237

238

239


240
241
242



243
244
245
246
247
248

249

250
251
252



253
254
255
256
257
258

259

260
261
262



263
264
265
266
267
268
269

270

271
272
273



274
275
276
277
278
279
280

281

282


283
284
285



286
287
288
289
290
291
292




293
294
295


296
297
298


299
300
301
302
303
304

305


306
307
308

309
310
311



312
313
314
315
316
317
318

319

320


321
322
323


324
325
326
327
328
329
330

331

332
333
334
335

336
337


338
339




-

-
-
+
+




-
+
-
-
+
-
-

-
-
+
+



-



-

+

-
-
-
+
+
+
+



-

-

+

-
-
+
+



-


-

+

-
-
-
+
+
+









+
-
-
-
-
+
+
+
+



-

-
+
-
-
+


-
+
-
-
-
+
+




-



-

+
-
-
-
-
+
+
+
+



-

-

+
-
-
-
+
+
+
+



-

-
+
-
-
+


-
-
+
+



-
-
-
+
+
-
-
+

-
-
-
-
+
+
+
+



-

-
+
-
-
+


-
-
+
+



-

-
-
+
+
-
-
+
+

-
-
-
+
+
+

-
+

-

-

+
-
-
-
+
+
+



-

-

+
-
-
-
-
+
+
+
+



-

-
+
-
-
+

-
-
-
-
+
+
+
+



-
-
-
-
+
+
+
-
-
+


-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-


-

+

-
-
-
+
+
+




-

-



-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-

-
+
-
-
+
+

-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-

-

+

-
-
-
+
+
+




-

-

+

-
-
-
+
+
+




-

-
+
-
-
+


-
-
-
+
+
+




-
-
-
-
+
+
+
-
-
+


-
-
+
+




-

-
-
+
+

-
+


-
-
-
+
+
+




-

-
+
-
-
+
+

-
-
+
+





-

-

+


-
+

-
-
+
+
#!/usr/bin/python

"""newsblur.py - An API wrapper library for newsblur.com"""

import cookielib
import simplejson
import urllib
import urllib2

import requests

__author__ = 'Dananjaya Ramanayake <dananjaya86@gmail.com>, spiffytech <spiffytechgmail.com>'
__version__ = "0.1"


nb_url = "http://www.newsblur.com/"
# Set up cookie handling so we can auth with the Newsblur API
cj = cookielib.LWPCookieJar()
cookies = None
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

nb_url = "http://newsblur.com/"

from gluon import current
print current.db

def login(username,password):
    '''
    
    Login as an existing user.
    If a user has no password set, you cannot just send any old password. 
    Required parameters, username and password, must be of string type.
    
    '''

    url = nb_url + 'api/login'
    params = urllib.urlencode({'username':username,'password':password})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    results = requests.post(url, data={"username": username, "password": password})
    global cookies
    cookies = results.cookies
    return simplejson.loads(results.content)

def logout():
    '''
    
    Logout the currently logged in user.
    
    '''

    url = nb_url + 'api/logout'
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def signup(username,password,email):
    '''
    
    Create a new user.
    All three required parameters must be of type string.
    
    '''

    url = nb_url + 'api/signup'
    params = urllib.urlencode({'signup_username':username,'signup_password':password,'signup_email':email})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'signup_username':username,'signup_password':password,'signup_email':email}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def search_feed(address,offset=1):
    '''
    
    Retrieve information about a feed from its website or RSS address.
    Parameter address must be of type string while parameter offset must be an integer.
    Will return a feed.
    
    '''

    url = nb_url + 'rss_feeds/search_feed?%s'
    params = urllib.urlencode({'address':address,'offset':offset})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'rss_feeds/search_feed'
    payload = {'address':address,'offset':offset}
    results = results.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def feeds(include_favicons=True,flat=False):
    '''
    
    Retrieve a list of feeds to which a user is actively subscribed.
        Includes the 3 unread counts (positive, neutral, negative), as well as optional favicons.
    Includes the 3 unread counts (positive, neutral, negative), as well as optional favicons.

        '''
    '''
    
    url = nb_url + 'reader/feeds'
    params = urllib.urlencode({'include_favicons':include_favicons,'flat':flat})
    payload = {'include_favicons':include_favicons,'flat':flat}
#    print url + " " + url % params
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def favicons(feeds=[1,2,3]):
    '''
    
    Retrieve a list of favicons for a list of feeds. 
    Used when combined with /reader/feeds and include_favicons=false, so the feeds request contains far less data. 
    Useful for mobile devices, but requires a second request. 
    
    '''
    
    url = nb_url + 'reader/favicons?%s'
    params = urllib.urlencode({'feeds':feeds})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/favicons'
    payload = {'feeds':feeds}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)
    
def id(id_no):
    '''
    
    Retrieve the original page from a single feed.
    
    '''
    
    url = nb_url + 'reader/page/%d' % id_no
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/page/' % id_no
    payload = {}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def refresh_feeds():
    '''
    
    Up-to-the-second unread counts for each active feed.
        Poll for these counts no more than once a minute.
    Poll for these counts no more than once a minute.
        
        '''
    '''

    url = nb_url + 'reader/refresh_feeds'
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def feeds_trainer(feed_id):
    '''
    
     Retrieves all popular and known intelligence classifiers.
        Also includes user's own classifiers.
    Retrieves all popular and known intelligence classifiers.
    Also includes user's own classifiers.
        
        '''
    '''

    url = nb_url + 'reader/feeds_trainer?%s'
    params = urllib.urlencode({'feed_id':feed_id})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/feeds_trainer'
    payload = {'feed_id':feed_id}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def statistics(id_no):
    '''
    
    If you only want a user's classifiers, use /classifiers/:id.
        Omit the feed_id to get all classifiers for all subscriptions.
    Omit the feed_id to get all classifiers for all subscriptions.
        
        '''
    '''

    url = nb_url + 'rss_feeds/statistics/%d' % id_no
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def feed_autocomplete(term):
    '''
    
    Get a list of feeds that contain a search phrase.
        Searches by feed address, feed url, and feed title, in that order.
        Will only show sites with 2+ subscribers.
    Searches by feed address, feed url, and feed title, in that order.
    Will only show sites with 2+ subscribers.
        
        '''
    '''

    url = nb_url + 'rss_feeds/feed_autocomplete?%'
    params = urllib.urlencode({'term':term})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    payload = {'term':term}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def feed(id=1):
def feed(id):
    '''
    
    Retrieve stories from a single feed.
    
    '''

    url = nb_url + 'reader/feed/%d' % id
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/feed/%s' % id
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def starred_stories(page=1):
    '''
    
    Retrieve a user's starred stories.
    
    '''
    
    url = nb_url + 'reader/starred_stories?%s'
    params = urllib.urlencode({'page':page})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/starred_stories'
    payload = {'page':page}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def river_stories(feeds,page=1,read_stories_count=0):
    '''
    
    Retrieve stories from a collection of feeds. This is known as the River of News.
        Stories are ordered in reverse chronological order.
    Stories are ordered in reverse chronological order.
        
        '''
    '''

    url = nb_url + 'reader/river_stories?%s'
    params = urllib.urlencode({'feeds':feeds,'page':page,'read_stories_count':read_stories_count})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/river_stories'
    payload = {'feeds':feeds,'page':page,'read_stories_count':read_stories_count}
    results = urllib2.urlopen(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def mark_story_as_read(story_id,feed_id):
    '''
    
     Mark stories as read.
        Multiple story ids can be sent at once.
        Each story must be from the same feed.
    Mark stories as read.
    Multiple story ids can be sent at once.
    Each story must be from the same feed.
        
        '''
    '''

    url = nb_url + 'reader/mark_story_as_read'
    params = urllib.urlencode({'story_id':story_id,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'story_id':story_id,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def mark_story_as_starred(story_id,feed_id):
    '''
    
    Mark a story as starred (saved).
    
    '''
    
    url = nb_url + 'reader/mark_story_as_starred'
    params = urllib.urlencode({'story_id':story_id,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'story_id':story_id,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def mark_all_as_read(days=0):
    '''
    
    Mark all stories in a feed or list of feeds as read.
    
    '''
    
    url = nb_url + 'reader/mark_all_as_read'
    params = urllib.urlencode({'days':days})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'days':days}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def add_url(url,folder='[Top Level]'):
    '''
    
    Add a feed by its URL. 
    Can be either the RSS feed or the website itself.
    
    '''
    
    url = nb_url + 'reader/add_url'
    params = urllib.urlencode({'url':url,'folder':folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'url':url,'folder':folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def add_folder(folder,parent_folder='[Top Level]'):
    '''
    
    Add a new folder.
    
    '''
    
    url = nb_url + 'reader/add_folder'
    params = urllib.urlencode({'folder':folder,'parent_folder':parent_folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folder':folder,'parent_folder':parent_folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def rename_feed(feed_title,feed_id):
    '''
    
    Rename a feed title. Only the current user will see the new title.
    
    '''
    
    url = nb_url + 'reader/rename_feed'
    params = urllib.urlencode({'feed_title':feed_title,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'feed_title':feed_title,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def delete_feed(feed_id,in_folder):
    '''
    
    Unsubscribe from a feed. Removes it from the folder.
        Set the in_folder parameter to remove a feed from the correct folder, in case the user is subscribed to the feed in multiple folders.
    Set the in_folder parameter to remove a feed from the correct folder, in case the user is subscribed to the feed in multiple folders.

        '''    
    '''    

    url = nb_url + 'reader/delete_feed'
    params = urllib.urlencode({'feed_id':feed_id,'in_folder':in_folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'feed_id':feed_id,'in_folder':in_folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def rename_folder(folder_to_rename,new_folder_name,in_folder):
    '''
    
    Rename a folder.
    
    '''
    
    url = nb_url + 'reader/rename_folder'
    params = urllib.urlencode({'folder_to_rename':folder_to_rename,'new_folder_name':new_folder_name,'in_folder':in_folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folder_to_rename':folder_to_rename,'new_folder_name':new_folder_name,'in_folder':in_folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def delete_folder(folder_to_delete,in_folder,feed_id):
    '''
    
    Delete a folder and unsubscribe from all feeds inside.
    
    '''
    
    url = nb_url + 'reader/delete_folder'
    params = urllib.urlencode({'folder_to_delete':folder_to_delete,'in_folder':in_folder,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folder_to_delete':folder_to_delete,'in_folder':in_folder,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def mark_feed_as_read(feed_id):
    '''
    
    Mark a list of feeds as read.
    
    '''
    
    url = nb_url + 'reader/mark_feed_as_read'
    params = urllib.urlencode({'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def save_feed_order(folders):
    '''
    
    Reorder feeds and move them around between folders.
        The entire folder structure needs to be serialized.
    The entire folder structure needs to be serialized.
        
        '''
    '''

    url = nb_url + 'reader/save_feed_order'
    params = urllib.urlencode({'folders':folders})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folders':folders}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def classifier(id_no):
    '''
    
        Get the intelligence classifiers for a user's site.
        Only includes the user's own classifiers. 
        Use /reader/feeds_trainer for popular classifiers.
    Get the intelligence classifiers for a user's site.
    Only includes the user's own classifiers. 
    Use /reader/feeds_trainer for popular classifiers.
        
        '''
    '''

    url = nb_url + 'classifier/%d' % id_no
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url)
    return simplejson.loads(results.content)


def classifier_save(like_type,dislike_type,remove_like_type,remove_dislike_type):
    '''
    
    Save intelligence classifiers (tags, titles, authors, and the feed) for a feed.
    
        '''
    '''
    
    url = nb_url + 'classifier/save'
    params = urllib.urlencode({'like_[TYPE]':like_type,
    payload = {'like_[TYPE]':like_type,
                   'dislike_[TYPE]':dislike_type,
                    'remove_like_[TYPE]':remove_like_type,
                   'remove_dislike_[TYPE]':remove_dislike_type})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
                   'remove_dislike_[TYPE]':remove_dislike_type}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def opml_export():
    '''
    
    Download a backup of feeds and folders as an OPML file.
        Contains folders and feeds in XML; useful for importing in another RSS reader.
    Contains folders and feeds in XML; useful for importing in another RSS reader.
        
        '''
    '''
    
    url = nb_url + 'import/opml_export'
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url)
    return simplejson.loads(results.content)



def opml_upload(opml_file):
    '''
    
    Upload an OPML file.
    
    '''
    
    url = nb_url + 'import/opml_upload'
    f = open(opml_file)
    params = urllib.urlencode({'file':f})
    payload = {'file':f}
    f.close()
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

Modified applications/mobileblur/modules/python-newsblur/newsblur.py from [9e60ae12cf] to [8c37485973].

1
2
3
4
5
6
7
8


9
10
11
12
13

14
15

16
17
18
19
20


21
22
23
24
25
26
27
28
29

30
31
32
33




34
35
36
37
38
39
40

41
42
43


44
45
46
47
48
49
50
51

52
53
54
55



56
57
58
59
60
61
62
63
64

65
66
67
68




69
70
71
72
73
74

75
76

77
78
79

80
81
82


83
84
85
86
87
88
89
90
91
92

93
94
95
96




97
98
99
100
101
102
103

104
105
106




107
108
109
110
111
112

113
114

115
116
117
118


119
120
121
122
123
124


125
126

127
128
129
130
131




132
133
134
135
136
137

138
139

140
141
142
143


144
145
146
147
148
149
150


151
152


153
154
155
156



157
158

159
160
161
162
163

164
165
166



167
168
169
170
171
172
173

174
175
176
177




178
179
180
181
182
183

184
185

186
187
188
189
190




191
192
193
194
195
196
197



198
199

200
201
202
203
204



205
206
207
208
209
210
211

212
213
214
215



216
217
218
219
220
221
222

223
224
225
226



227
228
229
230
231
232
233
234

235
236
237
238



239
240
241
242
243
244
245
246
247
248
249
250
251



252
253
254
255
256
257
258

259
260
261
262



263
264
265
266
267
268

269
270


271
272
273
274



275
276
277
278
279
280
281

282
283
284
285



286
287
288
289
290
291
292

293
294
295
296



297
298
299
300
301
302
303
304

305
306
307
308



309
310
311
312
313
314
315

316
317

318
319
320
321
322



323
324
325
326
327
328
329
330



331
332

333
334
335
336


337
338
339
340
341
342
343
344


345
346

347
348
349
350
351



352
353
354
355
356
357
358

359
360


361
362
363


364
365
366
367
368
369
370
371
372

373
374
375

376
377
378


1
2
3
4

5


6
7
8
9
10
11

12


13


14


15
16
17
18
19

20
21
22

23
24
25



26
27
28
29
30
31
32

33

34
35
36


37
38
39
40
41

42
43

44
45
46



47
48
49
50
51
52
53
54
55
56
57
58
59




60
61
62
63
64
65
66

67

68


69
70
71

72



73
74
75
76
77
78

79
80
81

82
83




84
85
86
87
88
89
90

91

92
93



94
95
96
97
98
99
100

101

102


103
104
105


106
107
108
109
110



111
112


113
114




115
116
117
118
119
120
121

122

123


124
125
126


127
128
129
130
131

132


133
134


135
136
137



138
139
140
141

142
143

144

145
146



147
148
149
150
151
152

153

154
155




156
157
158
159
160
161
162

163

164


165
166




167
168
169
170
171
172
173




174
175
176


177
178
179



180
181
182
183
184
185

186

187
188
189



190
191
192
193
194
195

196

197
198
199



200
201
202
203
204
205

206
207

208
209
210



211
212
213
214
215
216
217

218

219
220
221



222
223
224
225
226
227

228

229
230
231



232
233
234
235
236
237

238

239


240
241
242



243
244
245
246
247
248

249

250
251
252



253
254
255
256
257
258

259

260
261
262



263
264
265
266
267
268
269

270

271
272
273



274
275
276
277
278
279
280

281

282


283
284
285



286
287
288
289
290
291
292




293
294
295


296
297
298


299
300
301
302
303
304

305


306
307
308

309
310
311



312
313
314
315
316
317
318

319

320


321
322
323


324
325
326
327
328
329
330

331

332
333
334
335

336
337


338
339




-

-
-
+
+




-
+
-
-
+
-
-

-
-
+
+



-



-

+

-
-
-
+
+
+
+



-

-

+

-
-
+
+



-


-

+

-
-
-
+
+
+









+
-
-
-
-
+
+
+
+



-

-
+
-
-
+


-
+
-
-
-
+
+




-



-

+
-
-
-
-
+
+
+
+



-

-

+
-
-
-
+
+
+
+



-

-
+
-
-
+


-
-
+
+



-
-
-
+
+
-
-
+

-
-
-
-
+
+
+
+



-

-
+
-
-
+


-
-
+
+



-

-
-
+
+
-
-
+
+

-
-
-
+
+
+

-
+

-

-

+
-
-
-
+
+
+



-

-

+
-
-
-
-
+
+
+
+



-

-
+
-
-
+

-
-
-
-
+
+
+
+



-
-
-
-
+
+
+
-
-
+


-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-


-

+

-
-
-
+
+
+




-

-



-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-

-
+
-
-
+
+

-
-
-
+
+
+



-

-

+

-
-
-
+
+
+



-

-

+

-
-
-
+
+
+




-

-

+

-
-
-
+
+
+




-

-
+
-
-
+


-
-
-
+
+
+




-
-
-
-
+
+
+
-
-
+


-
-
+
+




-

-
-
+
+

-
+


-
-
-
+
+
+




-

-
+
-
-
+
+

-
-
+
+





-

-

+


-
+

-
-
+
+
#!/usr/bin/python

"""newsblur.py - An API wrapper library for newsblur.com"""

import cookielib
import simplejson
import urllib
import urllib2

import requests

__author__ = 'Dananjaya Ramanayake <dananjaya86@gmail.com>, spiffytech <spiffytechgmail.com>'
__version__ = "0.1"


nb_url = "http://www.newsblur.com/"
# Set up cookie handling so we can auth with the Newsblur API
cj = cookielib.LWPCookieJar()
cookies = None
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

nb_url = "http://newsblur.com/"

from gluon import current
print current.db

def login(username,password):
    '''
    
    Login as an existing user.
    If a user has no password set, you cannot just send any old password. 
    Required parameters, username and password, must be of string type.
    
    '''

    url = nb_url + 'api/login'
    params = urllib.urlencode({'username':username,'password':password})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    results = requests.post(url, data={"username": username, "password": password})
    global cookies
    cookies = results.cookies
    return simplejson.loads(results.content)

def logout():
    '''
    
    Logout the currently logged in user.
    
    '''

    url = nb_url + 'api/logout'
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def signup(username,password,email):
    '''
    
    Create a new user.
    All three required parameters must be of type string.
    
    '''

    url = nb_url + 'api/signup'
    params = urllib.urlencode({'signup_username':username,'signup_password':password,'signup_email':email})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'signup_username':username,'signup_password':password,'signup_email':email}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def search_feed(address,offset=1):
    '''
    
    Retrieve information about a feed from its website or RSS address.
    Parameter address must be of type string while parameter offset must be an integer.
    Will return a feed.
    
    '''

    url = nb_url + 'rss_feeds/search_feed?%s'
    params = urllib.urlencode({'address':address,'offset':offset})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'rss_feeds/search_feed'
    payload = {'address':address,'offset':offset}
    results = results.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def feeds(include_favicons=True,flat=False):
    '''
    
    Retrieve a list of feeds to which a user is actively subscribed.
        Includes the 3 unread counts (positive, neutral, negative), as well as optional favicons.
    Includes the 3 unread counts (positive, neutral, negative), as well as optional favicons.

        '''
    '''
    
    url = nb_url + 'reader/feeds'
    params = urllib.urlencode({'include_favicons':include_favicons,'flat':flat})
    payload = {'include_favicons':include_favicons,'flat':flat}
#    print url + " " + url % params
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def favicons(feeds=[1,2,3]):
    '''
    
    Retrieve a list of favicons for a list of feeds. 
    Used when combined with /reader/feeds and include_favicons=false, so the feeds request contains far less data. 
    Useful for mobile devices, but requires a second request. 
    
    '''
    
    url = nb_url + 'reader/favicons?%s'
    params = urllib.urlencode({'feeds':feeds})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/favicons'
    payload = {'feeds':feeds}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)
    
def id(id_no):
    '''
    
    Retrieve the original page from a single feed.
    
    '''
    
    url = nb_url + 'reader/page/%d' % id_no
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/page/' % id_no
    payload = {}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def refresh_feeds():
    '''
    
    Up-to-the-second unread counts for each active feed.
        Poll for these counts no more than once a minute.
    Poll for these counts no more than once a minute.
        
        '''
    '''

    url = nb_url + 'reader/refresh_feeds'
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def feeds_trainer(feed_id):
    '''
    
     Retrieves all popular and known intelligence classifiers.
        Also includes user's own classifiers.
    Retrieves all popular and known intelligence classifiers.
    Also includes user's own classifiers.
        
        '''
    '''

    url = nb_url + 'reader/feeds_trainer?%s'
    params = urllib.urlencode({'feed_id':feed_id})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/feeds_trainer'
    payload = {'feed_id':feed_id}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def statistics(id_no):
    '''
    
    If you only want a user's classifiers, use /classifiers/:id.
        Omit the feed_id to get all classifiers for all subscriptions.
    Omit the feed_id to get all classifiers for all subscriptions.
        
        '''
    '''

    url = nb_url + 'rss_feeds/statistics/%d' % id_no
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def feed_autocomplete(term):
    '''
    
    Get a list of feeds that contain a search phrase.
        Searches by feed address, feed url, and feed title, in that order.
        Will only show sites with 2+ subscribers.
    Searches by feed address, feed url, and feed title, in that order.
    Will only show sites with 2+ subscribers.
        
        '''
    '''

    url = nb_url + 'rss_feeds/feed_autocomplete?%'
    params = urllib.urlencode({'term':term})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    payload = {'term':term}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def feed(id=1):
def feed(id):
    '''
    
    Retrieve stories from a single feed.
    
    '''

    url = nb_url + 'reader/feed/%d' % id
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/feed/%s' % id
    results = requests.get(url, cookies=cookies)
    return simplejson.loads(results.content)

def starred_stories(page=1):
    '''
    
    Retrieve a user's starred stories.
    
    '''
    
    url = nb_url + 'reader/starred_stories?%s'
    params = urllib.urlencode({'page':page})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/starred_stories'
    payload = {'page':page}
    results = requests.get(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def river_stories(feeds,page=1,read_stories_count=0):
    '''
    
    Retrieve stories from a collection of feeds. This is known as the River of News.
        Stories are ordered in reverse chronological order.
    Stories are ordered in reverse chronological order.
        
        '''
    '''

    url = nb_url + 'reader/river_stories?%s'
    params = urllib.urlencode({'feeds':feeds,'page':page,'read_stories_count':read_stories_count})
    results = urllib2.urlopen(url % params).read()
    return simplejson.loads(results)
    url = nb_url + 'reader/river_stories'
    payload = {'feeds':feeds,'page':page,'read_stories_count':read_stories_count}
    results = urllib2.urlopen(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def mark_story_as_read(story_id,feed_id):
    '''
    
     Mark stories as read.
        Multiple story ids can be sent at once.
        Each story must be from the same feed.
    Mark stories as read.
    Multiple story ids can be sent at once.
    Each story must be from the same feed.
        
        '''
    '''

    url = nb_url + 'reader/mark_story_as_read'
    params = urllib.urlencode({'story_id':story_id,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'story_id':story_id,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def mark_story_as_starred(story_id,feed_id):
    '''
    
    Mark a story as starred (saved).
    
    '''
    
    url = nb_url + 'reader/mark_story_as_starred'
    params = urllib.urlencode({'story_id':story_id,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'story_id':story_id,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def mark_all_as_read(days=0):
    '''
    
    Mark all stories in a feed or list of feeds as read.
    
    '''
    
    url = nb_url + 'reader/mark_all_as_read'
    params = urllib.urlencode({'days':days})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'days':days}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def add_url(url,folder='[Top Level]'):
    '''
    
    Add a feed by its URL. 
    Can be either the RSS feed or the website itself.
    
    '''
    
    url = nb_url + 'reader/add_url'
    params = urllib.urlencode({'url':url,'folder':folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'url':url,'folder':folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def add_folder(folder,parent_folder='[Top Level]'):
    '''
    
    Add a new folder.
    
    '''
    
    url = nb_url + 'reader/add_folder'
    params = urllib.urlencode({'folder':folder,'parent_folder':parent_folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folder':folder,'parent_folder':parent_folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def rename_feed(feed_title,feed_id):
    '''
    
    Rename a feed title. Only the current user will see the new title.
    
    '''
    
    url = nb_url + 'reader/rename_feed'
    params = urllib.urlencode({'feed_title':feed_title,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'feed_title':feed_title,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def delete_feed(feed_id,in_folder):
    '''
    
    Unsubscribe from a feed. Removes it from the folder.
        Set the in_folder parameter to remove a feed from the correct folder, in case the user is subscribed to the feed in multiple folders.
    Set the in_folder parameter to remove a feed from the correct folder, in case the user is subscribed to the feed in multiple folders.

        '''    
    '''    

    url = nb_url + 'reader/delete_feed'
    params = urllib.urlencode({'feed_id':feed_id,'in_folder':in_folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'feed_id':feed_id,'in_folder':in_folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def rename_folder(folder_to_rename,new_folder_name,in_folder):
    '''
    
    Rename a folder.
    
    '''
    
    url = nb_url + 'reader/rename_folder'
    params = urllib.urlencode({'folder_to_rename':folder_to_rename,'new_folder_name':new_folder_name,'in_folder':in_folder})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folder_to_rename':folder_to_rename,'new_folder_name':new_folder_name,'in_folder':in_folder}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

def delete_folder(folder_to_delete,in_folder,feed_id):
    '''
    
    Delete a folder and unsubscribe from all feeds inside.
    
    '''
    
    url = nb_url + 'reader/delete_folder'
    params = urllib.urlencode({'folder_to_delete':folder_to_delete,'in_folder':in_folder,'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folder_to_delete':folder_to_delete,'in_folder':in_folder,'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def mark_feed_as_read(feed_id):
    '''
    
    Mark a list of feeds as read.
    
    '''
    
    url = nb_url + 'reader/mark_feed_as_read'
    params = urllib.urlencode({'feed_id':feed_id})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'feed_id':feed_id}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def save_feed_order(folders):
    '''
    
    Reorder feeds and move them around between folders.
        The entire folder structure needs to be serialized.
    The entire folder structure needs to be serialized.
        
        '''
    '''

    url = nb_url + 'reader/save_feed_order'
    params = urllib.urlencode({'folders':folders})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    payload = {'folders':folders}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def classifier(id_no):
    '''
    
        Get the intelligence classifiers for a user's site.
        Only includes the user's own classifiers. 
        Use /reader/feeds_trainer for popular classifiers.
    Get the intelligence classifiers for a user's site.
    Only includes the user's own classifiers. 
    Use /reader/feeds_trainer for popular classifiers.
        
        '''
    '''

    url = nb_url + 'classifier/%d' % id_no
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url)
    return simplejson.loads(results.content)


def classifier_save(like_type,dislike_type,remove_like_type,remove_dislike_type):
    '''
    
    Save intelligence classifiers (tags, titles, authors, and the feed) for a feed.
    
        '''
    '''
    
    url = nb_url + 'classifier/save'
    params = urllib.urlencode({'like_[TYPE]':like_type,
    payload = {'like_[TYPE]':like_type,
                   'dislike_[TYPE]':dislike_type,
                    'remove_like_[TYPE]':remove_like_type,
                   'remove_dislike_[TYPE]':remove_dislike_type})
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
                   'remove_dislike_[TYPE]':remove_dislike_type}
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)


def opml_export():
    '''
    
    Download a backup of feeds and folders as an OPML file.
        Contains folders and feeds in XML; useful for importing in another RSS reader.
    Contains folders and feeds in XML; useful for importing in another RSS reader.
        
        '''
    '''
    
    url = nb_url + 'import/opml_export'
    results = urllib2.urlopen(url).read()
    return simplejson.loads(results)
    results = requests.get(url)
    return simplejson.loads(results.content)



def opml_upload(opml_file):
    '''
    
    Upload an OPML file.
    
    '''
    
    url = nb_url + 'import/opml_upload'
    f = open(opml_file)
    params = urllib.urlencode({'file':f})
    payload = {'file':f}
    f.close()
    results = urllib2.urlopen(url,params).read()
    return simplejson.loads(results)
    results = requests.post(url, data=payload, cookies=cookies)
    return simplejson.loads(results.content)

Added applications/mobileblur/views/feeds/view.html version [de27b8829a].












1
2
3
4
5
6
7
8
9
10
11
+
+
+
+
+
+
+
+
+
+
+
{{left_sidebar_enabled=right_sidebar_enabled=False}}
{{extend 'layout.html'}}

<h1>Title: {{= feed["feed_title"] }}</h1>

{{ for story in stories: }}
    <a href="{{= URL(c="stories", f="view", vars=dict(story=story["id"], feed_id=feed["id"])) }}"><h2>{{= story["story_title"] }}</h2></a>
{{ pass }}

{{block left_sidebar}}New Left Sidebar Content{{end}}
{{block right_sidebar}}New Right Sidebar Content{{end}}

Added applications/mobileblur/views/stories/view.html version [859afcf521].










1
2
3
4
5
6
7
8
9
+
+
+
+
+
+
+
+
+
{{left_sidebar_enabled=right_sidebar_enabled=False}}
{{extend 'layout.html'}}

<a href="{{= story["story_permalink"] }}"><h1>{{= story["story_title"] }}</h1></a>

{{= XML(story["story_content"]) }}

{{block left_sidebar}}New Left Sidebar Content{{end}}
{{block right_sidebar}}New Right Sidebar Content{{end}}