Kaynağa Gözat

FAdd rating, comments, and date to article

JoostSijm 4 yıl önce
ebeveyn
işleme
1ba3aaec52

+ 15 - 4
src/vboo_info_bot/functions.py

@@ -6,16 +6,27 @@ from telegram.utils.helpers import escape_markdown
 def telegram_format_article(article):
     """Format article object for telegram"""
     title = '*[{}](https://m.rivalregions.com/#news/show/{})*'.format(
-        article['article_title'],
+        escape_markdown(article['article_title'], 2),
         article['article_id'],
     )
     author = '[{}](https://m.rivalregions.com/#slide/profile/{})'.format(
-        article['author_name'],
+        escape_markdown(article['author_name'], 2),
         article['author_id'],
     )
-    formatted_article = '{} by: {}\n_{}_'.format(
+    underline = '{}, rating: {}, comments: {}'.format(
+        escape_markdown(article['post_date'].strftime('%Y-%m-%d %H:%M'), 2),
+        article['rating'],
+        article['comments'],
+    )
+    if article['content_text'].strip():
+        article_content = '_{}_'.format(escape_markdown(article['content_text'][0:144].strip(), 2))
+    else:
+        article_content = ''
+    formatted_article = '{} by: {}\n{}\n{}'.format(
         title,
         author,
-        escape_markdown(article['content_text'][0:144].strip(), 2),
+        underline,
+        article_content,
     )
+    print(formatted_article)
     return formatted_article

+ 6 - 0
tests/test_vboo_info_bot_functions.py

@@ -32,6 +32,9 @@ def test_article_info_one(api_wrapper, article_keys):
     assert isinstance(response['content_text'], str), "Content text should be a string"
     assert isinstance(response['content_html'], str), "Content html should be a string"
     assert isinstance(response['language'], str), "Language should be a string"
+    assert isinstance(response['content_html'], str), "Content html should be a string"
+    assert isinstance(response['language'], str), "Language should be a string"
+    assert isinstance(response['rating'], int), "Rating should be an integer"
 
 @pytest.mark.vcr()
 def test_article_info_two(api_wrapper, article_keys):
@@ -52,3 +55,6 @@ def test_article_info_two(api_wrapper, article_keys):
     assert isinstance(response['content_text'], str), "Content text should be a string"
     assert isinstance(response['content_html'], str), "Content html should be a string"
     assert isinstance(response['language'], str), "Language should be a string"
+    assert isinstance(response['content_html'], str), "Content html should be a string"
+    assert isinstance(response['language'], str), "Language should be a string"
+    assert isinstance(response['rating'], int), "Rating should be an integer"