2929import turtle
3030import smtplib #library to send email
3131import PyPDF2
32+ from PIL import Image
3233
3334engine = pyttsx3 .init ()
3435voices = engine .getProperty ('voices' )
@@ -134,6 +135,36 @@ def readBooks():
134135 except :
135136 speak ("This Book is not Present!" )
136137
138+ def NasaNews (API_KEY ):
139+ speak ("On which day would you like to know ?" )
140+ Date = input ("Enter date as (2022-10-21): " )
141+
142+ speak ("Extracting Data From Nasa..." )
143+ Url = "https://api.nasa.gov/planetary/apod?api_key=" + str (API_KEY )
144+ Params = {'date' :str (Date )}
145+ r = requests .get (Url , params = Params )
146+
147+ Data = r .json ()
148+ print ("\n " )
149+ copyR = Data ['copyright' ]
150+ Info = Data ['explanation' ]
151+ Title = Data ['title' ]
152+ Image_Url = Data ['url' ]
153+ Image_r = requests .get (Image_Url )
154+ FileName = str (Date ) + '.jpg'
155+
156+ with open (FileName , 'wb' ) as f :
157+ f .write (Image_r .content )
158+ img = Image .open (FileName )
159+ img .show ()
160+
161+ speak (f"{ Title } is copyright by { copyR } \n " )
162+ speak (f"Acoording To Nasa : { Info } " )
163+
164+ print (f"CopyRight by { copyR } \n " )
165+ print (f"Title: { Title } \n " )
166+ print (f"FileName: { FileName } \n " )
167+
137168if __name__ == "__main__" :
138169 name = wishMe ()
139170 speak ("How May I Help You?" )
@@ -153,6 +184,17 @@ def readBooks():
153184 elif 'read books' in query :
154185 readBooks ()
155186
187+ elif 'nasa news' in query :
188+ speak ('Provide the path of text file having API KEY of NASA Organization.' )
189+ filePath = input ('Enter the path of API KEY text file: ' )
190+ try :
191+ with open (filePath , 'r' ) as file :
192+ API_KEY = file .read ().strip ()
193+ if API_KEY and API_KEY != "None" :
194+ NasaNews (API_KEY )
195+ except FileNotFoundError :
196+ print (f"Error: { filePath } not found." )
197+
156198 elif 'internet speed' in query :
157199 st = speedtest .Speedtest ()
158200 dl = bytes_to_mb (st .download ())
0 commit comments