Merge lp:~inspirated/fbfriendsgraph/testing into lp:fbfriendsgraph

Proposed by Kamran Riaz Khan
Status: Merged
Merge reported by: Kamran Riaz Khan
Merged at revision: not available
Proposed branch: lp:~inspirated/fbfriendsgraph/testing
Merge into: lp:fbfriendsgraph
Diff against target: 63 lines (+30/-2)
1 file modified
fbfriendsgraph.py (+30/-2)
To merge this branch: bzr merge lp:~inspirated/fbfriendsgraph/testing
Reviewer Review Type Date Requested Status
Kamran Riaz Khan Approve
Review via email: mp+19816@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Kamran Riaz Khan (inspirated) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'fbfriendsgraph.py'
2--- fbfriendsgraph.py 2010-02-16 15:03:58 +0000
3+++ fbfriendsgraph.py 2010-02-21 16:03:17 +0000
4@@ -3,6 +3,7 @@
5 mutual connections among them."""
6
7 import simplejson
8+import time
9 import thread
10 import threading
11 import urlparse
12@@ -132,6 +133,16 @@
13 writer = PNGWriter(filename, self.graph, self.mozbrowser)
14 writer.start()
15
16+ def get_connections(self, uid, friends):
17+ print 'Building connections for', uid
18+ ilist = [uid] * len(friends)
19+ try:
20+ iconnections = self.fb.friends.areFriends(ilist, friends)
21+ except Exception:
22+ return None
23+ else:
24+ return iconnections
25+
26 def run(self):
27 myfriends = self.fb.friends.get()
28 myfriendsinfo = self.fb.users.getInfo(myfriends, [u'name'])
29@@ -144,9 +155,14 @@
30 myfriends.remove(i)
31
32 edges = []
33+ reqs = {'limit' : 10, 'time' : time.time(), 'count' : 0}
34 for (num, i) in enumerate(myfriends):
35- ilist = [i] * len(myfriends)
36- iconnections = self.fb.friends.areFriends(ilist, myfriends)
37+ iconnections = None
38+ while iconnections == None and not self._stopped:
39+ iconnections = self.get_connections(i, myfriends)
40+
41+ if iconnections == None:
42+ break
43
44 self.data = (prepare_html(h1 = 'Creating friends connections',
45 h2 = '%.2f%%' % (float(num) / len(myfriends) * 100),
46@@ -166,6 +182,18 @@
47 edges.append((name1, name2))
48 gobject.idle_add(self.update)
49
50+ curtime = time.time()
51+ reqs['count'] = reqs['count'] + 1
52+ if reqs['count'] >= reqs['limit'] or curtime - reqs['time'] > 60:
53+ delay = 60 - (curtime - reqs['time'])
54+ if delay > 0:
55+ print 'Made', reqs['count'], 'requests in a minute'
56+ print 'Delaying for', delay, 'seconds'
57+ time.sleep(delay)
58+ print 'Continuing'
59+ reqs['count'] = 0
60+ reqs['time'] = curtime
61+
62 self.data = prepare_html(h1 = 'Friends connections parsed successfully')
63 gobject.idle_add(self.update)
64

Subscribers

People subscribed via source and target branches

to all changes: