-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
30 lines (27 loc) · 853 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import requests
import json
import nltk
from newspaper import Article
api_key = "your api key from NewsAPI"
url = f"https://newsapi.org/v2/top-headlines?sources=google-news&pageSize=1&apiKey={api_key}"
response = requests.get(url)
nltk.download('punkt')
if response.status_code == 200:
data = json.loads(response.text)
articles = data["articles"]
articleactual = articles[0]
url1 = articleactual["url"]
else:
print("Failed to fetch the news article")
article = Article(url1)
article.download()
article.parse()
print(url1)
with open('article.txt', 'w') as f:
f.write(article.text)
article.nlp()
with open('summary.txt', 'w') as f:
f.write(article.summary)
# TODO:
# 1. Use newspaper3k module to get keywords from article and fetch a relevant video.
# 2. Use pyttsx3 or any other text to speech service to get the audio.