Skip to content

Commit 50f1584

Browse files
committed
(it Fatches new Articles as per user request)
1 parent 4c06bd4 commit 50f1584

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Projects/News.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import requests
2+
import sys
3+
4+
def options():
5+
6+
print("-"*5,"Welcome To Daily News","-"*5)
7+
print("Enter 1 For Headlines")
8+
print("Enter 2 For Topic's")
9+
print("Enter 3 For Geting News From Your API :)")
10+
print("Enter 4 For Exit")
11+
12+
while True:
13+
14+
try:
15+
choose = int(input("Choose :"))
16+
match choose:
17+
18+
case 1:
19+
return Fatch_News()
20+
case 2:
21+
return search()
22+
case 3:
23+
return Fatch_Key()
24+
case 4:
25+
return Exit()
26+
27+
except ValueError:
28+
print("Enter Numbers Only")
29+
30+
def Fatch_Key():
31+
32+
user_key = input("Enter Your API Key :")
33+
return Fatch_News(user_key)
34+
35+
def search():
36+
pass
37+
38+
def Fatch_News(user_key = ""): #Enter Your API Key Heare
39+
40+
url = f"https://newsapi.org/v2/everything?q=keyword&apiKey={user_key}"
41+
request = requests.get(url)
42+
data = request.json()
43+
44+
news = []
45+
46+
for article in data["articles"]:
47+
48+
news.append({
49+
"Title" : article["title"],
50+
"Author" : article["author"],
51+
"Description" : article["description"]
52+
})
53+
54+
return news
55+
56+
57+
def Exit():
58+
59+
print("Thanks For Using PDF Tool Kit :)")
60+
sys.exit()
61+
62+
#Run These Command To Get Info About Type Of Data We Are Dealing With
63+
def Data_Info():
64+
65+
'''Tell Abut Type Of Data We Are Grtting From URL'''
66+
67+
url = "https://newsapi.org/v2/everything?q=keyword&apiKey=6495169f47154cfd83e9ac94ed500b0a"
68+
request = requests.get(url)
69+
70+
data = request.json()
71+
72+
print(type(data))
73+
print(data.keys())
74+
print(data['articles'][0].keys())
75+
76+
if __name__ == "__main__":
77+
options()
78+

0 commit comments

Comments
 (0)