Last active
August 29, 2015 14:09
-
-
Save jgillmanjr/f13c87cb4e1a7383007b to your computer and use it in GitHub Desktop.
Comment Scraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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