11import requests
22import sys
33
4+
45def options ():
56
6- print ("-" * 5 , "Welcome To Daily News" ,"-" * 5 )
7+ print ("-" * 5 , "Welcome To Daily News" , "-" * 5 )
78 print ("Enter 1 For Headlines" )
89 print ("Enter 2 For Topic's" )
910 print ("Enter 3 For Geting News From Your API :)" )
1011 print ("Enter 4 For Exit" )
1112
1213 while True :
13-
1414 try :
1515 choose = int (input ("Choose :" ))
1616 match choose :
17-
1817 case 1 :
1918 return Fatch_News ()
2019 case 2 :
@@ -23,34 +22,38 @@ def options():
2322 return Fatch_Key ()
2423 case 4 :
2524 return Exit ()
26-
25+
2726 except ValueError :
2827 print ("Enter Numbers Only" )
2928
29+
3030def Fatch_Key ():
3131
3232 user_key = input ("Enter Your API Key :" )
3333 return Fatch_News (user_key )
3434
35+
3536def search ():
3637 pass
3738
38- def Fatch_News (user_key = "" ): #Enter Your API Key Heare
39+
40+ def Fatch_News (user_key = "" ): # Enter Your API Key Heare
3941
4042 url = f"https://newsapi.org/v2/everything?q=keyword&apiKey={ user_key } "
4143 request = requests .get (url )
4244 data = request .json ()
4345
4446 news = []
45-
47+
4648 for article in data ["articles" ]:
49+ news .append (
50+ {
51+ "Title" : article ["title" ],
52+ "Author" : article ["author" ],
53+ "Description" : article ["description" ],
54+ }
55+ )
4756
48- news .append ({
49- "Title" : article ["title" ],
50- "Author" : article ["author" ],
51- "Description" : article ["description" ]
52- })
53-
5457 return news
5558
5659
@@ -59,10 +62,10 @@ def Exit():
5962 print ("Thanks For Using PDF Tool Kit :)" )
6063 sys .exit ()
6164
62- #Run These Command To Get Info About Type Of Data We Are Dealing With
63- def Data_Info ():
6465
65- '''Tell Abut Type Of Data We Are Grtting From URL'''
66+ # Run These Command To Get Info About Type Of Data We Are Dealing With
67+ def Data_Info ():
68+ """Tell Abut Type Of Data We Are Grtting From URL"""
6669
6770 url = "https://newsapi.org/v2/everything?q=keyword&apiKey=6495169f47154cfd83e9ac94ed500b0a"
6871 request = requests .get (url )
@@ -71,8 +74,8 @@ def Data_Info():
7174
7275 print (type (data ))
7376 print (data .keys ())
74- print (data ['articles' ][0 ].keys ())
77+ print (data ["articles" ][0 ].keys ())
78+
7579
7680if __name__ == "__main__" :
77- options ()
78-
81+ options ()
0 commit comments