-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
39 lines (32 loc) · 1.1 KB
/
test.py
File metadata and controls
39 lines (32 loc) · 1.1 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
import tweepy
import time
consumer_key = ''
consumer_secret = ''
key = ''
secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
#api = tweepy.API(auth, wait_on_rate_limit=True)
api = tweepy.API(auth)
FILE_NAME = 'last_seen.txt'
def read_last_seen(FILE_NAME):
file_read = open(FILE_NAME, 'r')
last_seen_id = int(file_read.read().strip())
file_read.close()
return last_seen_id
def store_last_seen(FILE_NAME, last_seen_id):
file_write = open(FILE_NAME, 'w')
file_write.write(str(last_seen_id))
file_write.close()
def reply():
tweets = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode='extended')
for tweet in reversed(tweets):
if '#randomtweet' in tweet.full_text.lower():
print("Replied to ID -" + str(tweet.id))
api.update_status('@' + tweet.user.screen_name + "Good Job!!!", tweet.id)
api.create_favorite(tweet.id)
api.retweet(tweet.id)
store_last_seen(FILE_NAME, tweet.id)
while True:
reply()
time.sleep(15)