-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtweet.py
33 lines (24 loc) · 904 Bytes
/
tweet.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
import tweepy
def store_last_id(tweet_id):
""" Stores a tweet id in text file """
with open('lastid', 'w') as fp:
fp.write(str(tweet_id))
def get_last_id():
""" Retrieve the list of tweets that were
already retweeted """
with open('lastid') as fp:
return fp.read()
if __name__ == '__main__':
auth = tweepy.OAuthHandler("your_consumer_key", "your_consumer_key_secret")
auth.set_access_token("your_access_token", "your_access_token_secret")
api = tweepy.API(auth)
try:
last_id = get_last_id()
except FileNotFoundError:
print("No retweet yet")
last_id = None
for tweet in tweepy.Cursor(api.search, q="fedoramagazine.org", since_id=last_id).items():
if tweet.user.name == 'Fedora Project':
store_last_id(tweet.id)
#tweet.retweet()
print(f'"{tweet.text}" was retweeted')