diff --git a/.gitignore b/.gitignore index c9f2884..6df9f3c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .env env __pycache__/* -telegram_bot/__pycache__/* \ No newline at end of file +telegram_bot/__pycache__/* +telegram_bot/news/__pycache__/* \ No newline at end of file diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index d73a7d4..4120f45 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -21,8 +21,12 @@ import time import sys import logging +<<<<<<< HEAD import news_fetcher import share_fetcher +======= +import news.news_fetcher as news +>>>>>>> 725f9806b7109b68219cc273edc616c1059ee4bb from telebot import types from dotenv import load_dotenv @@ -184,9 +188,9 @@ def send_news(message): user_id = int(message.from_user.id) #Get Information for user with this id - articles = news_fetcher.get_top_news_by_keyword(keyword) #tbd: get keyword from db + articles = news.get_top_news_by_keyword(keyword) #tbd: get keyword from db try: - formatted_article = news_fetcher.format_article(articles["articles"][0]) + formatted_article = news.format_article(articles["articles"][0]) except IndexError: bot.send_message(chat_id=user_id, text=f"no news currently available for keyword: {keyword}") return diff --git a/telegram_bot/news/article_example.json b/telegram_bot/news/article_example.json new file mode 100644 index 0000000..368fbf4 --- /dev/null +++ b/telegram_bot/news/article_example.json @@ -0,0 +1,32 @@ +{ + "status": "ok", + "totalResults": 1, + "articles": [ + { + "source": { + "id": "the-verge", + "name": "The Verge" + }, + "author": "Justine Calma", + "title": "EU Parliament backs off plans to phase out energy-hungry cryptocurrencies", + "description": "EU Parliament abandoned a measure in its proposed legislative framework for regulating cryptocurrencies that would have amounted to a de facto ban on energy-hungry networks like Bitcoin.", + "url": "https://www.theverge.com/2022/3/14/22977132/bitcoin-european-union-parliament-ban-proof-of-work-cryptocurrencies", + "urlToImage": "https://cdn.vox-cdn.com/thumbor/8bE-uBwwu-eXg-CcB6cOqcAGVDw=/0x286:4000x2380/fit-in/1200x630/cdn.vox-cdn.com/uploads/chorus_asset/file/23315944/834392892.jpg", + "publishedAt": "2022-03-14T23:40:25Z", + "content": "But Bitcoin is still under scrutiny \r\nPower cords for bitcoin mining machines are plugged into electrical outlets at a mining facility operated by Bitmain Technologies Ltd. in Ordos, Inner Mongolia, \u2026 [+5797 chars]" + }, + { + "source": { + "id": "the-verge", + "name": "The Verge" + }, + "author": "Justine Calma", + "title": "EU Parliament backs off plans to phase out energy-hungry cryptocurrencies", + "description": "EU Parliament abandoned a measure in its proposed legislative framework for regulating cryptocurrencies that would have amounted to a de facto ban on energy-hungry networks like Bitcoin.", + "url": "https://www.theverge.com/2022/3/14/22977132/bitcoin-european-union-parliament-ban-proof-of-work-cryptocurrencies", + "urlToImage": "https://cdn.vox-cdn.com/thumbor/8bE-uBwwu-eXg-CcB6cOqcAGVDw=/0x286:4000x2380/fit-in/1200x630/cdn.vox-cdn.com/uploads/chorus_asset/file/23315944/834392892.jpg", + "publishedAt": "2022-03-14T23:40:25Z", + "content": "But Bitcoin is still under scrutiny \r\nPower cords for bitcoin mining machines are plugged into electrical outlets at a mining facility operated by Bitmain Technologies Ltd. in Ordos, Inner Mongolia, \u2026 [+5797 chars]" + } + ] +} \ No newline at end of file diff --git a/telegram_bot/news_fetcher.py b/telegram_bot/news/news_fetcher.py similarity index 100% rename from telegram_bot/news_fetcher.py rename to telegram_bot/news/news_fetcher.py