Skip to content

Commit 38e73b1

Browse files
updated bot
1 parent 51f99e3 commit 38e73b1

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

apps/x-bot/bot.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,32 @@
1212
load_dotenv(dotenv_path=env_path)
1313

1414
def year_progress_bar():
15-
today = datetime.datetime.now(datetime.timezone.utc)
16-
year_start = datetime.datetime(today.year, 1, 1, tzinfo=datetime.timezone.utc)
17-
year_end = datetime.datetime(today.year + 1, 1, 1, tzinfo=datetime.timezone.utc)
18-
19-
days_passed = (today - year_start).days + 1
15+
today = datetime.datetime.utcnow()
16+
year_start = datetime.datetime(today.year, 1, 1)
17+
year_end = datetime.datetime(today.year + 1, 1, 1)
18+
2019
total_days = (year_end - year_start).days
21-
percent_passed = (today - year_start).total_seconds() / (year_end - year_start).total_seconds() * 100
22-
20+
days_passed = (today - year_start).days
21+
22+
percent_passed = (days_passed / total_days) * 100
23+
2324
bar_length = 20
24-
filled_length = int(bar_length * percent_passed // 100)
25-
25+
filled_length = int(bar_length * days_passed // total_days)
2626
bar = '█' * filled_length + '·' * (bar_length - filled_length)
2727

28-
post = (
29-
f"Year Progress: [{bar}] {percent_passed:.2f}%\n"
30-
f"Day {days_passed} of {total_days}"
28+
main_tweet = (
29+
f"{percent_passed:.2f}% of {today.year} has passed.\n"
30+
f"[{bar}]"
31+
)
32+
33+
promo_tweet = (
34+
f"Keep track of your time ⏳\n"
35+
f"https://theyearprogress.app"
3136
)
32-
return post
37+
38+
return main_tweet, promo_tweet
3339

34-
def tweet(message):
40+
def tweet(main_message, promo_message):
3541
try:
3642
print(f"Attempting to tweet with credentials:")
3743
print(f"API_KEY: {os.getenv('API_KEY')[:5]}...")
@@ -46,9 +52,18 @@ def tweet(message):
4652
access_token_secret=os.getenv('ACCESS_TOKEN_SECRET')
4753
)
4854

49-
response = client.create_tweet(text=message)
50-
print(f"Tweet posted successfully! Tweet ID: {response.data['id']}")
51-
return response
55+
# Post the main tweet
56+
main_response = client.create_tweet(text=main_message)
57+
print(f"Main tweet posted successfully! Tweet ID: {main_response.data['id']}")
58+
59+
# Post the promo reply as a thread
60+
promo_response = client.create_tweet(
61+
text=promo_message,
62+
in_reply_to_tweet_id=main_response.data['id']
63+
)
64+
print(f"Promo tweet posted successfully! Tweet ID: {promo_response.data['id']}")
65+
66+
return main_response, promo_response
5267
except Exception as e:
5368
print(f"Error posting tweet: {str(e)}")
5469
print(f"Error type: {type(e).__name__}")
@@ -57,6 +72,7 @@ def tweet(message):
5772
raise
5873

5974
if __name__ == "__main__":
60-
message = year_progress_bar()
61-
print(f"Generated message: {message}")
62-
tweet(message)
75+
main_message, promo_message = year_progress_bar()
76+
print(f"Generated main message: {main_message}")
77+
print(f"Generated promo message: {promo_message}")
78+
tweet(main_message, promo_message)

0 commit comments

Comments
 (0)