From af01a7e18303eb1516a4a8ea321b6d5a6c861465 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 15 Mar 2022 14:49:36 +0100 Subject: [PATCH 1/2] moved news_fetcher to new dir --- .gitignore | 3 ++- telegram_bot/bot.py | 6 +++--- telegram_bot/{ => news}/news_fetcher.py | 0 3 files changed, 5 insertions(+), 4 deletions(-) rename telegram_bot/{ => news}/news_fetcher.py (100%) 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 7b2bf8c..f1e321a 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -21,7 +21,7 @@ import time import sys import logging -import news_fetcher +import news.news_fetcher as news from telebot import types from dotenv import load_dotenv @@ -92,9 +92,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_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 From 725f9806b7109b68219cc273edc616c1059ee4bb Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 15 Mar 2022 14:54:17 +0100 Subject: [PATCH 2/2] added news example --- telegram_bot/news/article_example.json | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 telegram_bot/news/article_example.json 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