-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfarm.py
More file actions
53 lines (42 loc) · 1.53 KB
/
Copy pathfarm.py
File metadata and controls
53 lines (42 loc) · 1.53 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import tweepy
import datetime
import schedule
import time
import config
### CONFIG
bearer_token = config.BEARER_TOKEN
api_key = config.API_KEY
api_secret = config.API_SECRET
access_token = config.ACCESS_TOKEN
access_token_secret = config.ACCESS_TOKEN_SECRET
interval = config.INTERVAL
posted_tweets = set()
def initialize_tweepy():
client = tweepy.Client(bearer_token, api_key, api_secret, access_token, access_token_secret)
auth = tweepy.OAuthHandler(api_key, api_secret, access_token, access_token_secret)
api = tweepy.API(auth)
return client, api
def get_formatted_date():
current_datetime = datetime.datetime.now()
return current_datetime.strftime("%B %d, %Y %H:%M:%S")
def send_post():
client, _ = initialize_tweepy()
with open(('tweets.txt'), 'r') as file:
lines = file.readlines()
lines = [tweet for tweet in lines if tweet.strip() not in posted_tweets]
if lines:
tweet_text = lines.pop(0).strip() # Get and remove the first tweet from the list
client.create_tweet(text=f"{tweet_text}")
confirmation = f"'{tweet_text}' has been tweeted successfully on {get_formatted_date()}"
print(confirmation)
posted_tweets.add(tweet_text)
else:
print("No new tweets to post.")
def run_scheduler():
print('Farming has started')
schedule.every(interval).minutes.do(send_post) # Schedule the send_post function to run at regular intervals
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == "__main__":
run_scheduler()