/
tweetup
52 lines (43 loc) · 1.32 KB
/
tweetup
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
46
47
48
49
50
51
52
#!/usr/bin/env python
import fbconsole
import argparse
import os
import sys
flag_path = 0
flag_desc = 0
def update_it(status_update):
'''
function to update text status
'''
fbconsole.post('/me/feed', {'message': status_update})
def post_it(path, desc):
'''
function to post a image with or without description
'''
if desc == 1:
fbconsole.post('/me/photos', {'source':open(args.file), 'message':args.description})
else:
fbconsole.post('/me/photos', {'source':open(args.file)})
parser = argparse.ArgumentParser(description = 'Update your facebook status')
parser.add_argument("-f", "--file", type = str,
help = "Path to file to upload")
parser.add_argument("-d", "--description", type = str,
help = "Give the description of the file")
parser.add_argument("-p", "--post", type = str,
help = "Give the status update to post")
args = parser.parse_args()
fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins']
fbconsole.authenticate()
if args.file:
if os.path.exists(args.file):
flag_path = 1
if args.description:
flag_desc = 1
else:
print "File does not exist"
sys.exit(-1)
post_it(flag_path, flag_desc)
if args.post:
update_it(args.post)
fbconsole.logout()
sys.exit(0)