-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfbbirthdayReply.py
46 lines (35 loc) · 1.6 KB
/
fbbirthdayReply.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import json
from random import randint
#Needs the requests module.
#Use (sudo) pip install requests
#http://www.timestampgenerator.com/
#Use this link to generate the timeStamp.
timeStamp = 1426442399
# Initialize the Graph API with a valid access token
#Generate access token here: https://developers.facebook.com/tools/explorer/
accessToken = ''
query = " SELECT post_id, actor_id, created_time, message FROM stream WHERE \
filter_key = 'others' AND source_id = me() AND \
created_time > " + str(timeStamp) + " LIMIT 200 "
wishes = {'access_token': accessToken, 'q': query}
r = requests.get('https://graph.facebook.com/fql', params = wishes)
result = json.loads(r.text)
wallposts = result['data']
print str(len(wallposts)) + " to handle"
baseUrl = "https://graph.facebook.com/"
count = 1
for wallpost in wallposts:
forCheck = wallpost['message'].split()
if set(['happy', 'happiee', 'hbd', 'HBD', 'bday', 'birthday', 'returns']).intersection(set(forCheck)) > 0:
url = baseUrl + '%s/comments' % wallpost['post_id']
likesUrl = baseUrl + str(wallpost['post_id']) + "/likes/?access_token=" + accessToken + "&method=POST"
requests.post(likesUrl)
#Add as many replies you want inside this list.
#Make sure to change the randint() method's second parameter
#with the number of replies - 1.
messages = [ 'Thank you :)', 'Thanks :)']
comment = {'access_token': accessToken, 'message': messages[randint(0,1)]}
requests.post(url, data = comment)
print "Wall post %d done" % count
count += 1