-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposter.py
60 lines (48 loc) · 2.53 KB
/
poster.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
58
59
import schedule
import time
from datetime import datetime
from accounts.select_accounts import select_twitter_account
from accounts.get_credentials import get_twitter_account_details, get_all_twitter_account_details
from accounts.topics import get_topics_by_username
from bot.auth_provider import get_twitter_client
from bot.tweet_poster import post_tweet
from gpt.generate_prompt import create_tweet_prompt
from gpt.gpt_client import use_gpt
from utils.print_color_utils import print_header, print_error, print_success, print_warning, print_info, print_highlight, print_debug, get_user_input
def post_to_single_account():
username = select_twitter_account("Select account to post to:")
credentials = get_twitter_account_details(username=username)
topics = get_topics_by_username(username=username)
prompt = create_tweet_prompt(keywords=topics)
tweet = use_gpt(prompt=prompt)
print(tweet)
client = get_twitter_client(account_data=credentials)
post_tweet(client=client, tweet=tweet)
def single_account_poster_helper(username):
try:
credentials = get_twitter_account_details(username=username)
topics = get_topics_by_username(username=username)
prompt = create_tweet_prompt(keywords=topics)
tweet = use_gpt(prompt=prompt)
print(tweet)
client = get_twitter_client(account_data=credentials)
post_tweet(client=client, tweet=tweet)
print_success(f"Successfully posted tweet for {username} at {datetime.now().strftime('%H:%M')}")
except Exception as e:
print_error(f"Failed to post tweet: {str(e)}")
def post_5_strategy():
username = select_twitter_account("Select account to post 5 viral tweets to:")
# Schedule 5 tweets at the optimal times of the day
schedule.every().day.at("09:00").do(single_account_poster_helper, username=username)
schedule.every().day.at("12:00").do(single_account_poster_helper, username=username)
schedule.every().day.at("15:00").do(single_account_poster_helper, username=username)
schedule.every().day.at("18:00").do(single_account_poster_helper, username=username)
schedule.every().day.at("21:00").do(single_account_poster_helper, username=username)
print_success(f"Scheduled 5 viral tweets per day for {username}")
# Inform the user about the next scheduled tweet
next_run_time = min(job.next_run for job in schedule.jobs)
print_info(f"Next tweet will be posted at {next_run_time.strftime('%H:%M')}")
# Run the scheduled tasks
while True:
schedule.run_pending()
time.sleep(1)