File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ # path: twitter_bot/twitter_manager.py
2
+ import datetime
3
+ import calendar
4
+ from .twitter_api import get_twitter_api
5
+
6
+ class TwitterManager :
7
+ def __init__ (self ):
8
+ self .api = get_twitter_api ()
9
+ self .tweets_count = 0
10
+
11
+ def post_job (self , job ):
12
+ tweet_message = f"{ job ['title' ]} at { job ['company' ]} - { job ['location' ]} More info: { job ['job_url' ]} "
13
+ try :
14
+ self .api .update_status (tweet_message )
15
+ self .tweets_count += 1
16
+ print ("Tweet posted success." )
17
+ except Exception as e :
18
+ print (f"Failed to post tweet: { str (e )} " )
19
+
20
+ def can_post_today (self ):
21
+ today = datetime .date .today ()
22
+ _ , num_days = calendar .monthrange (today .year , today .month )
23
+ tweets_per_day = 1500 / num_days # Average number of tweets per num_days
24
+ days_left = num_days - today .day + 1
25
+
26
+ return self .tweets_count < tweets_per_day * (today .day - 1 )
27
+
28
+ def reset_monthly_count (self ):
29
+ self .tweets_count = 0
You can’t perform that action at this time.
0 commit comments