forked from GodSuperK/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweeter.py
68 lines (59 loc) · 1.34 KB
/
tweeter.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Author: Shreyas Daniel (shreydan)
Install: tweepy - "pip install tweepy"
API: Create a twitter app "apps.twitter.com" to get your OAuth requirements.
Version: 1.0
Tweet text and pics directly from the terminal.
"""
import tweepy, os
def getStatus():
lines = []
while True:
line = raw_input()
if line:
lines.append(line)
else:
break
status = '\n'.join(lines)
return status
def tweetthis(type):
if type == "text":
print "Enter your tweet "+user.name
tweet = getStatus()
try:
api.update_status(tweet)
except Exception as e:
print e
return
elif type == "pic":
print "Enter pic path "+user.name
pic = os.path.abspath(raw_input())
print "Enter status "+user.name
title = getStatus()
try:
api.update_with_media(pic, status=title)
except Exception as e:
print e
return
print "\n\nDONE!!"
def initialize():
global api, auth, user
ck = "here" # consumer key
cks = "here" # consumer key SECRET
at = "here" # access token
ats = "here" # access token SECRET
auth = tweepy.OAuthHandler(ck,cks)
auth.set_access_token(at,ats)
api = tweepy.API(auth)
user = api.me()
def main():
doit = int(raw_input("\n1. text\n2. picture\n"))
initialize()
if doit == 1:
tweetthis("text")
elif doit == 2:
tweetthis("pic")
else:
print "OK, Let's try again!"
main()
main()