workaround for connection problems

This commit is contained in:
Rripped
2022-03-29 12:04:49 +02:00
parent 4c517998ba
commit 4afd1ab87b
3 changed files with 39 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ __date__ = "15.03.2022"
__version__ = "0.0.1"
__license__ = "None"
from ast import parse
import sys
import os
import json
@@ -13,6 +14,7 @@ import requests
from newsapi import NewsApiClient
from dotenv import load_dotenv
import urllib.parse as urlparse
load_dotenv()
@@ -31,8 +33,9 @@ def get_top_news_by_keyword(keyword):
Returns:
JSON/dict: dict containing articles
"""
top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en')
"""
keyword_url = urlparse.quote(keyword)
top_headlines = newsapi.get_top_headlines(q=keyword_url, sources=str_sources, language='en')
return top_headlines
def format_article(article):