Skip to content

Commit a2e427b

Browse files
refactored
1 parent 1e8ba62 commit a2e427b

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/tasks/schedulers.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,20 @@ async def send_tweet(self, tweet: dict[str, str]):
123123
async def do_create_tweet(self, article: ArticleData) -> dict[str, str]:
124124
self._logger.info("Creating Tweets")
125125
# Extract ticker symbols as hashtags
126-
hashtags = ' '.join(['#' + ticker for ticker in article.tickers])
127-
internal_link: str = f"https://eod-stock-api.site/blog/financial-news/tweets/{article.uuid}"
128-
business_api_link: str = "https://bit.ly/financial-business-news-api"
129-
# Create the tweet text with hashtags
130-
_title: str = "Financial & Business News API"
131-
_crop_len: int = self._max_status_length - len(_title) - 6
132-
133-
if self._count % 2 == 0:
134-
if article.sentiment and article.sentiment.article_tldr:
135-
tweet_text = f"{_title}\n{article.sentiment.article_tldr[0: _crop_len]}"
136-
else:
137-
tweet_text: str = f"{_title}\n-{article.title}\n - FOR API Integration: {business_api_link}"
126+
if article.tickers:
127+
hashtags = ''.join(['#' + ticker for ticker in article.tickers])
128+
elif article.sentiment.stock_codes:
129+
_codes = article.sentiment.stock_codes
130+
hashtags = ''.join(['#' + ticker for ticker in _codes])
138131
else:
139-
if article.sentiment and article.sentiment.article_tldr:
140-
tweet_text = f"{_title}\n{article.sentiment.article_tldr[0: _crop_len]}"
141-
else:
142-
tweet_text: str = f"Financial & Business News API\n{hashtags}\n- {article.title}\n{internal_link}"
132+
hashtags = ""
143133

144-
self._count += 1
134+
# Create the tweet text with hashtags
135+
_title: str = "Financial & Business News API"
136+
_crop_len: int = self._max_status_length - len(_title) - 6 - len(hashtags)
137+
tweet_body = f"{article.sentiment.article_tldr[: _crop_len]}" if article.sentiment.article_tldr else article.title
145138

146-
if len(tweet_text) > self._max_status_length:
147-
tweet_text = f"Financial & Business News API\n- {article.title}\n{internal_link}"
139+
tweet_text = f"{_title}\n-{tweet_body}...\n{hashtags}"
148140

149141
if article.thumbnail.resolutions:
150142
_url: str = article.thumbnail.resolutions[0].url

0 commit comments

Comments
 (0)