29
29
import turtle
30
30
import smtplib #library to send email
31
31
import PyPDF2
32
+ from PIL import Image
32
33
33
34
engine = pyttsx3 .init ()
34
35
voices = engine .getProperty ('voices' )
@@ -134,6 +135,36 @@ def readBooks():
134
135
except :
135
136
speak ("This Book is not Present!" )
136
137
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
+
137
168
if __name__ == "__main__" :
138
169
name = wishMe ()
139
170
speak ("How May I Help You?" )
@@ -153,6 +184,17 @@ def readBooks():
153
184
elif 'read books' in query :
154
185
readBooks ()
155
186
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
+
156
198
elif 'internet speed' in query :
157
199
st = speedtest .Speedtest ()
158
200
dl = bytes_to_mb (st .download ())
0 commit comments