Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/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()
print("current sha1sum {0}".format(hasher.hexdigest()))
# get token from
ACCESS_TOKEN = os.environ.get("fb_access_token")
pk_group_id = '373189689430865'
post_id = '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']
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
# pop
elected_name = candidates.pop(0)
# print
print("{0} got {1}".format(elected_name, item))
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
You can’t perform that action at this time.