-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbirthday_ninja.py
45 lines (38 loc) · 1.59 KB
/
birthday_ninja.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
import random
TOKEN = $FACEBOOK_ACCESS_TOKEN
comment_list = ['Thanks :)', 'Thank you so much :D', 'Thanx :)', 'Thanks for making my day special! :)', 'Thanks a bunch!', 'Thanks so much. Hope you are doing great :)']
def get_birthday_feed():
# Facebook graph API returns only 25 links at once.
init_url = 'https://graph.facebook.com/me/feed?access_token=' + TOKEN
flag = True
while(flag):
result = json.loads((requests.get(init_url)).text)
#print result
for i in range(0, len(result['data'])):
print result['data'][i]['from']['name'] + " : " + result['data'][i]['message']
print "(R)eply, (n)ext or (e)xit?"
user_response = str(raw_input())
if user_response == 'R' or user_response == 'r':
# comment
comment = comment_list[random.randint(0, len(comment_list)-1)]
print "Replying With : " + comment
r = requests.post("https://graph.facebook.com/" + result['data'][i]['id'].split("_")[1] + "/comments?access_token=" + TOKEN + "&message=" + comment)
#like
r = requests.post("https://graph.facebook.com/" + result['data'][i]['id'].split("_")[1] + "/likes?access_token=" + TOKEN)
print r
# send a post
elif user_response == 'n' or user_response == "N":
print "Skipping this guy"
elif user_response == "e" or user_response == "E":
print "Exiting"
flag = False
break
else:
print "No valid input"
# get next set of data
init_url = result['paging']['next']
# execute main
if __name__ == '__main__':
get_birthday_feed()