File tree 2 files changed +67
-0
lines changed 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ * .conf
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python3
2
+ # vim: set fileencoding=utf-8 :
3
+
4
+ # require `pip3 install twitter`
5
+ # require `export PYTHONIOENCODING=utf-8`
6
+
7
+ import twitter
8
+ import sys
9
+ import os
10
+
11
+ import configparser
12
+ import codecs
13
+
14
+ import traceback
15
+
16
+ BASE_DIR = os .path .dirname (os .path .abspath (__file__ ))
17
+ DEBUG = True
18
+
19
+ CONSUMER_KEY = None
20
+ CONSUMER_SECRET = None
21
+ TOKEN = None
22
+ TOKEN_SECRET = None
23
+
24
+ def log (msg ):
25
+ if DEBUG :
26
+ f = open (BASE_DIR + "/run.log" ,"a" )
27
+ f .write (str (msg ) + "\n " )
28
+ f .close ()
29
+
30
+ def post (word ):
31
+ auth = twitter .OAuth (
32
+ consumer_key = CONSUMER_KEY ,
33
+ consumer_secret = CONSUMER_SECRET ,
34
+ token = TOKEN ,
35
+ token_secret = TOKEN_SECRET )
36
+ t = twitter .Twitter (auth = auth )
37
+ word = word .replace ('\\ n' ,"\n " )
38
+ log (word )
39
+ ret = t .statuses .update (status = word )
40
+ log (ret )
41
+
42
+ if __name__ == '__main__' :
43
+ # Get Credential Key
44
+ try :
45
+ parser = configparser .ConfigParser ()
46
+ parser .readfp (codecs .open (BASE_DIR + '/post_twitter.conf' , "r" , "utf8" ))
47
+ CONSUMER_KEY = parser ['key' ]['consumer_key' ]
48
+ CONSUMER_SECRET = parser ['key' ]['consumer_secret' ]
49
+ TOKEN = parser ['key' ]['token' ]
50
+ TOKEN_SECRET = parser ['key' ]['token_secret' ]
51
+ except :
52
+ log ("Failed while parsing config" )
53
+ log (traceback .format_exc ())
54
+ exit (- 1 )
55
+
56
+ # Create PostMessage from args
57
+ argvs = sys .argv
58
+ argc = len (argvs )
59
+ if argc < 2 :
60
+ log ("No Message" )
61
+ exit (- 1 )
62
+ argvs .pop (0 )
63
+ argw = ""
64
+ for argv in argvs :
65
+ argw = argw + " " + argv
66
+ post (argw )
You can’t perform that action at this time.
0 commit comments