Created
December 26, 2016 03:30
-
-
Save darjeeling/3e75526e980647146a5d22adaf04262d to your computer and use it in GitHub Desktop.
get_comment_user_list.py
This file contains hidden or 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
#!/usr/bin/env python | |
import sys, os | |
from facepy import GraphAPI | |
import numpy | |
import re | |
import hashlib | |
url_match = 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' | |
current_filename = __file__ | |
hasher = hashlib.md5() | |
hasher.update(open(current_filename,'rb').read()) | |
print("current sha1sum {0}".format(hasher.hexdigest())) | |
# get token from https://developers.facebook.com/tools/explorer/ | |
ACCESS_TOKEN = os.environ.get("fb_access_token") | |
pk_group_id = '373189689430865' | |
post_id = '1178417535574739' | |
# https://www.facebook.com/groups/pythonkorea/permalink/1178417535574739/ | |
path = '1178417535574739/comments' | |
candidates = set() | |
graph = GraphAPI(ACCESS_TOKEN) | |
data = graph.get(path) | |
caldata = {} | |
for comment in data['data']: | |
if 'http' in comment['message']: | |
urls = re.findall(url_match, comment['message']) | |
writer_name = comment['from']['name'] | |
candidates.add(writer_name) | |
url = urls[0] | |
caldata[writer_name] = url | |
# run the vote | |
# pop 3 times | |
candidates = list(candidates) | |
for item in ['line diary','starbucks1','starbucks2']: | |
# run shuffle | |
numpy.random.shuffle(candidates) | |
# pop | |
elected_name = candidates.pop(0) | |
print("{0} got {1}".format(elected_name, item)) | |
print("\n\n\nurls") | |
for writer, url in caldata.items(): | |
print("{0} {1}".format(writer,url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment