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
=== modified file 'fbfriendsgraph.py'
--- fbfriendsgraph.py 2010-02-16 15:03:58 +0000
+++ fbfriendsgraph.py 2010-02-21 16:03:17 +0000
@@ -3,6 +3,7 @@
3mutual connections among them."""3mutual connections among them."""
44
5import simplejson5import simplejson
6import time
6import thread7import thread
7import threading8import threading
8import urlparse9import urlparse
@@ -132,6 +133,16 @@
132 writer = PNGWriter(filename, self.graph, self.mozbrowser)133 writer = PNGWriter(filename, self.graph, self.mozbrowser)
133 writer.start()134 writer.start()
134135
136 def get_connections(self, uid, friends):
137 print 'Building connections for', uid
138 ilist = [uid] * len(friends)
139 try:
140 iconnections = self.fb.friends.areFriends(ilist, friends)
141 except Exception:
142 return None
143 else:
144 return iconnections
145
135 def run(self):146 def run(self):
136 myfriends = self.fb.friends.get()147 myfriends = self.fb.friends.get()
137 myfriendsinfo = self.fb.users.getInfo(myfriends, [u'name'])148 myfriendsinfo = self.fb.users.getInfo(myfriends, [u'name'])
@@ -144,9 +155,14 @@
144 myfriends.remove(i)155 myfriends.remove(i)
145156
146 edges = []157 edges = []
158 reqs = {'limit' : 10, 'time' : time.time(), 'count' : 0}
147 for (num, i) in enumerate(myfriends):159 for (num, i) in enumerate(myfriends):
148 ilist = [i] * len(myfriends)160 iconnections = None
149 iconnections = self.fb.friends.areFriends(ilist, myfriends)161 while iconnections == None and not self._stopped:
162 iconnections = self.get_connections(i, myfriends)
163
164 if iconnections == None:
165 break
150166
151 self.data = (prepare_html(h1 = 'Creating friends connections',167 self.data = (prepare_html(h1 = 'Creating friends connections',
152 h2 = '%.2f%%' % (float(num) / len(myfriends) * 100),168 h2 = '%.2f%%' % (float(num) / len(myfriends) * 100),
@@ -166,6 +182,18 @@
166 edges.append((name1, name2))182 edges.append((name1, name2))
167 gobject.idle_add(self.update)183 gobject.idle_add(self.update)
168184
185 curtime = time.time()
186 reqs['count'] = reqs['count'] + 1
187 if reqs['count'] >= reqs['limit'] or curtime - reqs['time'] > 60:
188 delay = 60 - (curtime - reqs['time'])
189 if delay > 0:
190 print 'Made', reqs['count'], 'requests in a minute'
191 print 'Delaying for', delay, 'seconds'
192 time.sleep(delay)
193 print 'Continuing'
194 reqs['count'] = 0
195 reqs['time'] = curtime
196
169 self.data = prepare_html(h1 = 'Friends connections parsed successfully')197 self.data = prepare_html(h1 = 'Friends connections parsed successfully')
170 gobject.idle_add(self.update)198 gobject.idle_add(self.update)
171199

Subscribers

People subscribed via source and target branches

to all changes: