Skip to content

Instantly share code, notes, and snippets.

@phwd
Last active December 17, 2015 19:19
Show Gist options
  • Save phwd/5659357 to your computer and use it in GitHub Desktop.
Save phwd/5659357 to your computer and use it in GitHub Desktop.
Wow such horrible python..
from facepy import GraphAPI
from facepy.exceptions import *
import time
import urllib
import json
import facepy
fb_dump = open('lumpfb.txt', 'w')
graph = GraphAPI('MY_ACCESS_TOKEN')
def fqlit(limit):
all_posts = []
offset = 0
friendsquery = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '
linksquery = 'SELECT backdated_time, can_backdate, caption, created_time, owner, owner_comment, picture, summary, title, url FROM link WHERE owner IN (SELECT uid2 FROM #friendsquery) AND (strpos(lower(summary),\'trinidad\') >=0 OR strpos(lower(owner_comment),\'trinidad\') >=2 ) LIMIT 20'
t0 = time.time()
batch_request = []
try:
my_friends = graph.get("me?fields=friends.limit("+str(limit)+")")
counter = len(my_friends["friends"]["data"])
while counter > 0 :
friendsquery0 = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '+ str(offset)
the_query = '{"friendsquery":"'+friendsquery0+'","linksquery":"'+linksquery+'"}'
batch_item = {"method":"GET","relative_url":"fql?q=" + the_query}
batch_request.append(batch_item)
offset = offset + 20
counter = counter - 20
my_posts = graph.batch(batch_request)
for post in my_posts:
all_posts = all_posts + post['data']
t1 = time.time()
print t1-t0
except facepy.exceptions.FacepyError, e:
print e.message
for x in range(0,301,10):
fqlit(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment