You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python command-line tool that fetches recent news articles based on a search query using NewsAPI and summarizes the article content using extractive summarization. You can also save the summaries to a text file.
# Python command-line tool that fetches recent news articles based on a search query using NewsAPI and summarizes the article content using extractive summarization. You can also save the summaries to a text file.
3
+
4
+
# (requires API key in .env file)
5
+
6
+
importrequests
7
+
importos
8
+
importsys
9
+
fromdotenvimportload_dotenv
10
+
fromsumma.summarizerimportsummarize
11
+
12
+
13
+
defmain():
14
+
15
+
# loads .env variables
16
+
load_dotenv()
17
+
API_KEY=os.getenv("NEWS_API_KEY")
18
+
19
+
# check validity of command-line arguments
20
+
try:
21
+
iflen(sys.argv) ==2:
22
+
news_query=sys.argv[1]
23
+
else:
24
+
raiseIndexError()
25
+
exceptIndexError:
26
+
sys.exit('Please provide correct number of command-line arguments')
27
+
28
+
try:
29
+
# get number of articles from user
30
+
whileTrue:
31
+
try:
32
+
num_articles=int(input('Enter number of articles: '))
0 commit comments