24
24
25
25
FIVE_MINUTE = 300
26
26
27
- DEFAULT_TWEETS : list [dict [str , str ]] = [
28
- dict (
29
- status = """
30
- EOD Stock Market API
31
-
32
- - Exchange & Ticker Data
33
- - (EOD) Stock Data
34
- - Fundamental Data
35
- - Stock Options And Splits Data
36
- - Financial News API
37
- - Social Media Trend Data For Stocks
38
-
39
- Create A free API Key today
40
- https://eod-stock-api.site/plan-descriptions/basic
41
- """ ,
42
- media_ids = ["1647575420009603073" ]),
43
- dict (
44
- status = """
45
- Financial & Business News API
46
-
47
- - Articles By UUID
48
- - Articles By Publishing Date
49
- - Articles By Stock Tickers
50
- - Articles By Exchange
51
- - Get List of Exchanges & Tickers
52
- - Get List of Publishers & Articles By Publisher
53
-
54
- Create A free API Key today
55
- https://bit.ly/financial-business-news-api
56
- """ ,
57
- media_ids = ["1647575420009603073" ])
27
+
28
+ def compose_default_tweets (api_name , tweet_lines , media_ids = None ):
29
+ tweet_text = "\n " .join (tweet_lines )
30
+ tweet = {"status" : f"{ api_name } \n { tweet_text } " }
31
+ if media_ids :
32
+ tweet ["media_ids" ] = media_ids
33
+ return tweet
34
+
35
+
36
+ DEFAULT_TWEETS = [
37
+ compose_default_tweets ("EOD Stock Market API" , [
38
+ "- Exchange & Ticker Data" ,
39
+ "- (EOD) Stock Data" ,
40
+ "- Fundamental Data" ,
41
+ "- Stock Options And Splits Data" ,
42
+ "- Financial News API" ,
43
+ "- Social Media Trend Data For Stocks" ,
44
+ "Create A free API Key today" ,
45
+ "https://eod-stock-api.site/plan-descriptions/basic"
46
+ ], media_ids = ["1647575420009603073" ]),
47
+ compose_default_tweets ("Financial & Business News API" , [
48
+ "- Articles By UUID" ,
49
+ "- Articles By Publishing Date" ,
50
+ "- Articles By Stock Tickers" ,
51
+ "- Articles By Exchange" ,
52
+ "- Get List of Exchanges & Tickers" ,
53
+ "- Get List of Publishers & Articles By Publisher" ,
54
+ "Create A free API Key today" ,
55
+ "https://bit.ly/financial-business-news-api"
56
+ ], media_ids = ["1647575420009603073" ])
58
57
]
59
58
60
59
@@ -96,6 +95,7 @@ async def send_tweet(self, tweet: dict[str, str]):
96
95
return True
97
96
except Forbidden as e :
98
97
self ._logger .error (f"Error updating status: { str (e )} " )
98
+ self ._logger .info (f"Tweet that Caused the Errror : { tweet .get ('status' )} " )
99
99
return False
100
100
101
101
async def do_create_tweet (self , article : ArticleData ) -> dict [str , str ]:
@@ -105,16 +105,9 @@ async def do_create_tweet(self, article: ArticleData) -> dict[str, str]:
105
105
internal_link : str = f"https://eod-stock-api.site/blog/financial-news/tweets/{ article .uuid } "
106
106
107
107
# Create the tweet text with hashtags
108
- tweet_text : str = f"""Financial & Business News API
109
- { hashtags }
110
- - { article .title }
111
- { internal_link }
112
- """
108
+ tweet_text : str = f"Financial & Business News API\n { hashtags } \n - { article .title } \n { internal_link } "
113
109
if len (tweet_text ) > self ._max_status_length :
114
- tweet_text = f"""Financial & Business News API
115
- - { article .title }
116
- { internal_link }
117
- """
110
+ tweet_text = f"Financial & Business News API\n - { article .title } \n { internal_link } "
118
111
119
112
if article .thumbnail .resolutions :
120
113
_url : str = article .thumbnail .resolutions [0 ].url
@@ -149,7 +142,8 @@ async def create_tweets(self):
149
142
tweet : dict [str , str ] = await self .do_create_tweet (article = ArticleData (** article ))
150
143
self ._logger .info (f"Tweet : { tweet } " )
151
144
await self ._tweet_queue .put (tweet )
152
- except ValidationError :
145
+ except ValidationError as e :
146
+ self ._logger .error (f"Error Creating Tweet: { str (e )} " )
153
147
pass
154
148
155
149
async def run (self ):
@@ -166,9 +160,11 @@ async def run(self):
166
160
167
161
tweet : dict [str , str ] | None = await self ._tweet_queue .get ()
168
162
if tweet :
169
- while tweet and not await self .send_tweet (tweet = tweet ):
163
+ tweet_sent = await self .send_tweet (tweet = tweet )
164
+ while not tweet_sent :
170
165
await asyncio .sleep (delay = self ._error_delay )
171
- tweet : str = await self ._tweet_queue .get ()
166
+ tweet : dict [str , str ] = await self ._tweet_queue .get ()
167
+ tweet_sent = await self .send_tweet (tweet = tweet )
172
168
173
169
return None
174
170
0 commit comments