Skip to content

Instantly share code, notes, and snippets.

@jgillmanjr
Last active Aug 29, 2015
Embed
What would you like to do?
Comment Scraper
import facebook
import json
import iso8601
import pytz
tZone = pytz.timezone('US/Eastern')
token = raw_input('User Token: ')
threadID = raw_input('Thread ID: ')
graph = facebook.GraphAPI(token)
thread = graph.get_object(threadID)
commentFile = open(threadID + '-comments.txt', 'w')
stringIter = []
for comment in thread['comments']['data']:
dtime = iso8601.parse_date(comment['created_time']).astimezone(tZone)
stringIter.append('|Poster: ' + comment['from']['name'] + '\n')
#stringIter.append('Time: ' + str(dtime.month) + '/' + str(dtime.day) + '/' + str(dtime.year) + '@' + str(dtime.hour - timeOffset) + ':' + str(dtime.minute) + ':' + str(dtime.second) + ' GMT' + str(timeOffset) + '\n')
stringIter.append('|Time: ' + dtime.strftime('%d%b%y @ %H:%M:%S%Z') + '\n|')
stringIter.append('\n|' + comment['message'].replace('\n', '\n|') + '\n' + '|_________________________\n\n')
for line in stringIter:
commentFile.write(line.encode('utf-8'))
#print line.encode('utf-8')
commentFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment