Skip to content

Commit 5eaa51a

Browse files
authored
Merge pull request #36 from Capstone-Projects-2024-Spring/ISH-96--Image-URL
ISH -96 Return news stories.
2 parents 69b4504 + 60f267c commit 5eaa51a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

app/app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ def get_all_devices(device_type):
9898
else:
9999
return None
100100

101+
def get_recent_news():
102+
api_key = 'f39bbfdee666491fbde90584b53cd919'
103+
news_url = f'https://newsapi.org/v2/top-headlines?country=us&apiKey={api_key}&pageSize=5'
104+
105+
response = requests.get(news_url)
106+
107+
if response.status_code == 200:
108+
news_data = response.json()
109+
articles = []
110+
111+
for article in news_data['articles']:
112+
article_info = {
113+
'title': article['title'],
114+
'content': article['description'],
115+
'url': article['url'],
116+
'image_url': article.get('urlToImage', '')
117+
}
118+
articles.append(article_info)
119+
120+
return articles
121+
else:
122+
return None
123+
101124

102125
def black_image(img):
103126
black_screen = np.zeros_like(img)

0 commit comments

Comments
 (0)