Skip to content

Instantly share code, notes, and snippets.

@ismaild
Created February 7, 2012 08:16
Show Gist options
  • Save ismaild/1758208 to your computer and use it in GitHub Desktop.
Save ismaild/1758208 to your computer and use it in GitHub Desktop.
Search Facebook Graph API for specific string and write to CSV
#!/usr/bin/env python
# encoding: utf-8
"""
fbsearch.py
ismail@zyelabs.net
"""
import facepy
import csv
fieldnames = [u'category', u'name', u'id']
sstring = 'recipes'
stype = 'page'
f = open(sstring + '.csv','w')
writer = csv.DictWriter(f, fieldnames)
graph = facepy.GraphAPI()
z = graph.search(sstring,stype,page=True)
for col in z:
for rec in col['data']:
for item in rec:
rec[item] = rec[item].encode('ascii', 'ignore')
writer.writerow(rec)
print rec
print "writing...."
print "All done"
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment