harao-ml commited on
Commit
d8ab53f
·
verified ·
1 Parent(s): 4ce3575

Update gather_news.py

Browse files
Files changed (1) hide show
  1. gather_news.py +4 -0
gather_news.py CHANGED
@@ -6,12 +6,16 @@
6
 
7
  import requests
8
  import feedparser
 
9
 
10
  def fetch_articles_newsapi(topic):
11
  """
12
  Fetch articles from NewsAPI based on the provided topic.
13
  """
14
  url = 'https://newsapi.org/v2/everything'
 
 
 
15
  params = {
16
  'apiKey': api_key,
17
  'language': 'en',
 
6
 
7
  import requests
8
  import feedparser
9
+ import os
10
 
11
  def fetch_articles_newsapi(topic):
12
  """
13
  Fetch articles from NewsAPI based on the provided topic.
14
  """
15
  url = 'https://newsapi.org/v2/everything'
16
+ api_key = os.environ.get("api_key") # Make sure the key name matches what's in HF settings
17
+ if not api_key:
18
+ raise ValueError("API_KEY is not set in environment variables.")
19
  params = {
20
  'apiKey': api_key,
21
  'language': 'en',