Bot features #7

Merged
H4CK3R-01 merged 7 commits from bot-features into main 2022-03-17 15:29:16 +00:00
2 changed files with 10 additions and 4 deletions
Showing only changes of commit 536bdf3bd6 - Show all commits

View File

@ -205,7 +205,7 @@ def send_news(message):
:rtype: none
"""
keyword = "business"
keyword = "bitcoin"
user_id = int(message.from_user.id)
#Get Information for user with this id

View File

@ -9,6 +9,7 @@ __license__ = "None"
import sys
import os
import json
import requests
from newsapi import NewsApiClient
from dotenv import load_dotenv
@ -16,7 +17,12 @@ from dotenv import load_dotenv
load_dotenv()
# Init
newsapi = NewsApiClient(api_key=os.getenv('NEWS_API_KEY'))
api_key = os.getenv('NEWS_API_KEY')
newsapi = NewsApiClient(api_key=api_key)
source_json = requests.get(f"https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&language=en").json()
sources = source_json["sources"]
str_sources = ",".join([source["id"] for source in sources])
def get_top_news_by_keyword(keyword):
"""get top news to keyword
@ -26,7 +32,7 @@ def get_top_news_by_keyword(keyword):
Returns:
JSON/dict: dict containing articles
"""
top_headlines = newsapi.get_top_headlines(q=keyword, sources='bbc-news,the-verge,cnn,buzzfeed,fox', language='en')
top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en')
return top_headlines
def format_article(article):
@ -49,6 +55,6 @@ if __name__ == '__main__':
print("fetching top news by keyword business...")
articles = get_top_news_by_keyword("business")
articles = get_top_news_by_keyword("bitcoin")
formatted_article = format_article(articles["articles"][0])
print(formatted_article)