Skip to content

Instantly share code, notes, and snippets.

@jgillmanjr
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgillmanjr/f13c87cb4e1a7383007b to your computer and use it in GitHub Desktop.
Save jgillmanjr/f13c87cb4e1a7383007b to your computer and use it in GitHub Desktop.
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