-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitterbot.py
38 lines (25 loc) · 939 Bytes
/
twitterbot.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
import tweepy
auth = tweepy.OAuthHandler("auth1",
"auth_secret")
auth.set_access_token("token",
"token_secret")
botapi = tweepy.API(auth)
try:
botapi.verify_credentials()
print("Auth OK")
except:
print("Deu merda na auth mano :/")
usuario = input("Quem vc deseja responder? ")
msg = input("Oq vc deseja mandar? ")
userid = botapi.get_user(usuario)
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
print(f'{usuario} tweetou: {status.text}')
try:
for tweet in tweepy.Cursor(botapi.user_timeline, id=usuario).items(1):
botapi.update_status(f'@{usuario} {msg}', tweet.id)
except tweepy.TweepError as e:
print(e.reason)
streamListener = StreamListener()
myStream = tweepy.Stream(auth=botapi.auth, listener=streamListener)
myStream.filter(follow=[userid.id_str], is_async=True)