added small error handling
This commit is contained in:
@@ -20,9 +20,13 @@ load_dotenv()
|
||||
# Init
|
||||
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])
|
||||
try:
|
||||
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])
|
||||
except KeyError:
|
||||
print("Error: Could not get sources")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def get_all_news_by_keyword(keyword, from_date="2000-01-01"):
|
||||
|
Reference in New Issue
Block a user