-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitter_api.py
More file actions
38 lines (29 loc) · 908 Bytes
/
twitter_api.py
File metadata and controls
38 lines (29 loc) · 908 Bytes
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
#!/usr/bin/env python2
##https://blog.twitter.com/developer
import tweepy
from subprocess import Popen, PIPE
def get_api(cfg):
auth = tweepy.OAuthHandler(cfg['consumer_key'], cfg['consumer_secret'])
auth.set_access_token(cfg['access_token'], cfg['access_token_secret'])
return tweepy.API(auth)
def main():
# Fill in the values noted in previous step here
cfg = {
"consumer_key" : "value",
"consumer_secret" : "value",
"access_token" : "value",
"access_token_secret" : "value"
}
api = get_api(cfg)
## system info ##
uptime = "/usr/bin/uptime"
p = Popen([uptime, '-p'],stdout=PIPE)
for x in p.stdout:
mas = list(x)
mas1=''.join(mas)
tweet = "Your PI system uptime is {} ".format(mas1)
status = api.update_status(status=tweet)
#print(tweet)
# Yes, tweet is called 'status' rather confusing
if __name__ == "__main__":
main()