-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (36 loc) · 1.31 KB
/
main.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
import json
import tweepy
import asyncio
import logging
import threading
logging.basicConfig(level=logging.INFO)
async def main():
credentials = json.load(open("credentials.json"))
dictionary = json.load(open("dictionary.json"))
counter = 0
counter_lock = threading.Lock()
consumer_key = credentials["api_key"]
consumer_secret = credentials["api_key_secret"]
access_token = credentials["access_token"]
access_token_secret = credentials["access_token_secret"]
bearer_token = credentials["bearer_token"]
client = tweepy.Client(
bearer_token=bearer_token,
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret,
)
while counter < len(dictionary):
message = "I am " + dictionary[counter]
try:
client.create_tweet(text=message)
logging.info(f"Successfully tweeted: {message}")
except tweepy.TweepError as e:
logging.error(f"Error while sending tweet: {e}")
await asyncio.sleep(60) # Wait 1 minute before trying again
with counter_lock:
counter += 1
await asyncio.sleep(30 * 60) # Wait 30 minutes before sending the next tweet
if __name__ == '__main__':
asyncio.run(main())