-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweeter.py
More file actions
235 lines (203 loc) · 9.09 KB
/
tweeter.py
File metadata and controls
235 lines (203 loc) · 9.09 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import tweepy
import webbrowser
import time
import api_stuff
import os.path
from os import path
import sys
def check_auth():
if path.exists(os.path.join(os.path.dirname(__file__), 'auth.txt')):
f = open(os.path.join(os.path.dirname(__file__), 'auth.txt'), "r")
auth_lines = f.readlines()
f.close()
login(auth_lines)
else:
auth_lines = []
register(auth_lines)
def register(auth_lines):
consumer_key = api_stuff.consumer_key
consumer_secret = api_stuff.consumer_secret
callback_uri = 'oob'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret, callback_uri)
redirect_url = auth.get_authorization_url()
print(redirect_url)
webbrowser.open(redirect_url)
user_pin_input = input("pin:")
auth.get_access_token(user_pin_input)
api = tweepy.API(auth)
me = api.me()
print("Welcome " + me.screen_name + "!")
# save user
f = open(os.path.join(os.path.dirname(__file__), 'auth.txt'), "a")
if len(auth_lines) > 0:
f.write("\n" + me.screen_name + " " + auth.access_token + " " + auth.access_token_secret)
else:
f.write(me.screen_name + " " + auth.access_token + " " + auth.access_token_secret)
tweeter(api)
def login(auth_lines):
print("Who do you want to login as?")
option = 0
for line in auth_lines:
print(str(option) + " - " + line.split()[0])
option += 1
print(str(option) + " - " + "New User\n")
choice = input("nmbr(/q):")
try:
choice = int(choice)
except ValueError:
print("canceled.")
sys.exit()
if choice > len(auth_lines)-1:
register(auth_lines)
else:
line = auth_lines[choice]
print("Logging in as " + line.split()[0] + "...")
access_token = line.split()[1]
access_token_secret = line.split()[2]
consumer_key = api_stuff.consumer_key
consumer_secret = api_stuff.consumer_secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
me = api.me()
print("Welcome " + me.screen_name + "!")
tweeter(api)
def tweeter(api):
while True:
print("(h for help)")
cmd = input()
if cmd == "h": #help
print("""
tw --Tweet.
[>] enter your Tweet.
re --Reply.
[ID:] ID of the Tweet that you want to reply to.
[>] enter your reply.
sre --More stable reply. (not needed anymore)
[ID:] ID of the Tweet that you want to reply to.
[ats:] all mentioned @'s
[>] enter your reply.
crt --Comment-Retweet.
[URL:] URL of the Tweet that you want to comment retweet.
[>] enter your comment.
itw --Image-Tweet
[count:] how many images you want to attach. (1-4)
[path:] path of your image. The images will be in the order in which you add them.
[>] enter your Tweet.
ire --Image-Reply
[ID:] ID of the Tweet that you want to reply to.
[count:] how many images you want to attach. (1-4)
[path:] path of your image. The images will be in the order in which you add them.
[>] enter your reply.
isre --Image-Stable-Reply (not needed anymore)
[ID:] ID of the Tweet that you want to reply to.
[ats:] all mentioned @'s
[count:] how many images you want to attach. (1-4)
[path:] path of your image. The images will be in the order in which you add them.
[>] enter your reply.
icrt --Image-Comment-Retweet.
[URL:] URL of the Tweet that you want to comment retweet.
[count:] how many images you want to attach. (1-4)
[path:] path of your image. The images will be in the order in which you add them.
[>] enter your comment.
q --Quit.
h --Help.""")
elif cmd == "tw": #tweet
tweet = input(">")
api.update_status(tweet)
elif cmd == "re": #reply
tw_id = input("ID:")
tweet = input(">")
api.update_status(tweet, in_reply_to_status_id = tw_id, auto_populate_reply_metadata = True)
elif cmd == "sre": #reply
tw_id = input("ID:")
ats = input("ats:")
tweet = input(">")
api.update_status(ats + " " + tweet, in_reply_to_status_id = tw_id)
elif cmd == "crt": #comment-RT
url = input("URL:")
tweet = input(">")
api.update_status(tweet + " " + url)
elif cmd == "itw": #image+tweet
count = int(input("count:"))
if count > 3:
img_obj1 = api.media_upload(input("path:"))
if count > 2:
img_obj2 = api.media_upload(input("path:"))
if count > 1:
img_obj3 = api.media_upload(input("path:"))
if count > 0:
img_obj4 = api.media_upload(input("path:"))
tweet = input(">")
if count >= 4:
api.update_status(tweet, media_ids=[img_obj1.media_id_string, img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string])
if count == 3:
api.update_status(tweet, media_ids=[img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string])
if count == 2:
api.update_status(tweet, media_ids=[img_obj3.media_id_string, img_obj4.media_id_string])
if count == 1:
api.update_status(tweet, media_ids=[img_obj4.media_id_string])
elif cmd == "ire": #image+reply
tw_id = input("ID:")
count = int(input("count:"))
if count > 3:
img_obj1 = api.media_upload(input("path:"))
if count > 2:
img_obj2 = api.media_upload(input("path:"))
if count > 1:
img_obj3 = api.media_upload(input("path:"))
if count > 0:
img_obj4 = api.media_upload(input("path:"))
tweet = input(">")
if count >= 4:
api.update_status(tweet, media_ids=[img_obj1.media_id_string, img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string], in_reply_to_status_id = tw_id, auto_populate_reply_metadata = True)
if count == 3:
api.update_status(tweet, media_ids=[img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string], in_reply_to_status_id = tw_id, auto_populate_reply_metadata = True)
if count == 2:
api.update_status(tweet, media_ids=[img_obj3.media_id_string, img_obj4.media_id_string], in_reply_to_status_id = tw_id, auto_populate_reply_metadata = True)
if count == 1:
api.update_status(tweet, media_ids=[img_obj4.media_id_string], in_reply_to_status_id = tw_id, auto_populate_reply_metadata = True)
elif cmd == "isre": #image+stable reply
tw_id = input("ID:")
ats = input("ats:")
count = int(input("count:"))
if count > 3:
img_obj1 = api.media_upload(input("path:"))
if count > 2:
img_obj2 = api.media_upload(input("path:"))
if count > 1:
img_obj3 = api.media_upload(input("path:"))
if count > 0:
img_obj4 = api.media_upload(input("path:"))
tweet = input(">")
if count >= 4:
api.update_status(ats + " " + tweet, media_ids=[img_obj1.media_id_string, img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string], in_reply_to_status_id = tw_id)
if count == 3:
api.update_status(ats + " " + tweet, media_ids=[img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string], in_reply_to_status_id = tw_id)
if count == 2:
api.update_status(ats + " " + tweet, media_ids=[img_obj3.media_id_string, img_obj4.media_id_string], in_reply_to_status_id = tw_id)
if count == 1:
api.update_status(ats + " " + tweet, media_ids=[img_obj4.media_id_string], in_reply_to_status_id = tw_id)
elif cmd == "icrt": #image+comment-RT
url = input("URL:")
count = int(input("count:"))
if count > 3:
img_obj1 = api.media_upload(input("path:"))
if count > 2:
img_obj2 = api.media_upload(input("path:"))
if count > 1:
img_obj3 = api.media_upload(input("path:"))
if count > 0:
img_obj4 = api.media_upload(input("path:"))
tweet = input(">")
if count >= 4:
api.update_status(tweet + url, media_ids=[img_obj1.media_id_string, img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string])
if count == 3:
api.update_status(tweet + url, media_ids=[img_obj2.media_id_string, img_obj3.media_id_string, img_obj4.media_id_string])
if count == 2:
api.update_status(tweet + url, media_ids=[img_obj3.media_id_string, img_obj4.media_id_string])
if count == 1:
api.update_status(tweet + url, media_ids=[img_obj4.media_id_string])
elif cmd == "q": #quit
break
check_auth()