-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOT.py
57 lines (41 loc) · 1.73 KB
/
BOT.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
# Retweet bot for Twitter, using Python and Tweepy.
# Search query via hashtag or keyword.
import tweepy
from time import sleep
CONSUMER_KEY = 'i73CZaLFIv2iuzUSWwAZ4n3qj'
CONSUMER_SECRET = 'Za4BuBZEL8sGPwKq2kDZsS5vieG8qvH0bdgBWM2OdbjOi5Root'
ACCESS_KEY = '1261021151754682375-WFJgum4dUxrErkxUzLabrGitnYQPgj'
ACCESS_SECRET = 'sBiyzO60LzMwDC7X6x2XaJBRcoPOzxT7JDypbcptHD1Ob'
# change your Twitter application keys, tokens, and secrets
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
FILE_NAME = 'last_seen_id.txt'
i=0
def retrieve_last_seen_id(file_name):
f_read = open(file_name, 'r')
last_seen_id = int(f_read.read().strip())
f_read.close()
return last_seen_id
def store_last_seen_id(last_seen_id, file_name):
f_write = open(file_name, 'w')
f_write.write(str(last_seen_id))
f_write.close()
return
#q – the search query string
#item(5) - how many of tweets you want to retweet
#If you want to search multiple terms then separate it with OR keyword.
#for single tearm search use q='example'
for tweet in tweepy.Cursor(api.search, q='#akgec OR #AKGEC').items(999):
try:
print('\nbot by @prakanshu'+ ' ' + tweet.user.screen_name + '.' + 'Attempting to retweet.')
tweet.retweet()
print('Retweet published successfully.')
sleep(5)
#sleep(5) - tweet interval (In Second)
# Some basic error handling. Will print out why retweet failed, into your terminal.
except tweepy.TweepError as error:
print('\nError. Retweet not successful. Reason: ')
print(error.reason)
except StopIteration:
break