Skip to content

Instantly share code, notes, and snippets.

@phwd
Created May 27, 2013 18:36
Show Gist options
  • Save phwd/5658464 to your computer and use it in GitHub Desktop.
Save phwd/5658464 to your computer and use it in GitHub Desktop.
This is a horrible script. You were warned.
from facepy import GraphAPI
import time
import urllib
import json
fb_dump = open('dumpfb.txt', 'w')
graph = GraphAPI('MY_ACCESS_TOKEN')
all_posts = []
offset = 0
friendsquery = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '+ str(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()
try:
my_posts = graph.fql({'friendsquery': friendsquery, 'linksquery': linksquery})
while my_posts["data"][0]["fql_result_set"]:
all_posts = all_posts + my_posts["data"]
offset = offset + 20
friendsquery = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '+ str(offset)
my_posts = graph.fql({'friendsquery': friendsquery, 'linksquery': linksquery})
t1 = time.time()
print t1-t0
fb_dump.write(json.dumps(all_posts, indent=4))
except GraphAPI.OAuthError, e:
print e.message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment