Last active
December 20, 2015 23:58
-
-
Save chhantyal/6216358 to your computer and use it in GitHub Desktop.
Thank all the people who wished you birthday on Facebook
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 requests | |
import json | |
import random | |
AFTER = 1388952000 | |
TOKEN = 'Token' | |
def get_posts(): | |
""" | |
Returns dictionary of id, first names of people who posted on my wall | |
between start and end time | |
""" | |
query = ("SELECT post_id, actor_id, message FROM stream WHERE " | |
"filter_key = 'others' AND source_id = me() AND " | |
"created_time > %s LIMIT 200" % AFTER) | |
payload = {'q': query, 'access_token': TOKEN} | |
r = requests.get('https://graph.facebook.com/fql', params=payload) | |
result = json.loads(r.text) | |
return result['data'] | |
def commentall(wallposts): | |
""" | |
Comments thank you on all posts | |
""" | |
for wallpost in wallposts: | |
r = requests.get('https://graph.facebook.com/%s' % | |
wallpost['actor_id']) | |
url = 'https://graph.facebook.com/%s/comments' % wallpost['post_id'] | |
user = json.loads(r.text) | |
words = ['Thank you,', 'Thanks'] | |
message = '%s %s :)' % (random.choice(words), user['first_name']) | |
payload = {'access_token': TOKEN, 'message': message} | |
s = requests.post(url, data=payload) | |
print "You thanked %s" % user['first_name'] | |
if __name__ == '__main__': | |
commentall(get_posts()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment