-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebot.py
44 lines (35 loc) · 1 KB
/
facebot.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
#!/usr/bin/env python
import sys
import random
import fbconsole as fb
#GID = '102305819969381' # myfrog
GID = '504896499520960' # pan group
def post_msg(fb, path, msg):
fb.post(path, {"message": msg})
def get_msgs(fb, path):
return fb.get(path)
def get_rand_msg(fn):
return random.sample(open(fn).readlines(), 1)[0].strip()
def get_weekday():
import datetime
return datetime.datetime.today().weekday()
def main():
if len(sys.argv) < 2:
print "usage: %s <message_file>"
sys.exit()
fn = sys.argv[1]
fb.AUTH_SCOPE = ['publish_stream', 'publish_checkins', 'user_groups']
print "[i] authentication"
fb.authenticate()
msg = get_rand_msg(fn)
if get_weekday() == 5:
path = '/%s/feed' % GID
else:
print "[i] get first message"
msgs = get_msgs(fb, '/%s/feed' % GID )
mid = msgs['data'][0]['id']
path = '/%s/comments' % mid
post_msg(fb, path , msg)
print "[i] message sent"
if __name__ == '__main__':
main()