Last active
August 16, 2022 09:28
-
-
Save KaushikShresth07/d58022e9876f5043a5507645463a08f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests # pip install requests | |
import os | |
import matplotlib.pyplot as plt # pip install matplotlib | |
import cartopy.crs as ccrs # pip install cartopy | |
from PIL import Image # pip install PIL | |
def NasaNews(Date,Api_Key,pathNow,PathToSave): | |
Url = "https://api.nasa.gov/planetary/apod?api_key=" + str(Api_Key) | |
Params = {'date':str(Date)} | |
r = requests.get(Url,params = Params) | |
Data = r.json() | |
Info = Data['explanation'] | |
Title = Data['title'] | |
Image_Url = Data['url'] | |
Image_r = requests.get(Image_Url) | |
FileName = str(Date) + '.jpg' | |
with open(FileName,'wb') as f: | |
f.write(Image_r.content) | |
Path_1 = str(pathNow) + str(FileName) | |
Path_2 = str(PathToSave) + str(FileName) | |
os.rename(Path_1, Path_2) | |
img = Image.open(Path_2) | |
img.show() | |
return f''' | |
{Title}. | |
{Info}''' | |
def Summary(Boby): | |
name = str(Boby) | |
url = "https://hubblesite.org/api/v3/glossary/" + str(name) | |
r = requests.get(url) | |
Data = r.json() | |
if len(Data) != 0: | |
retur = Data['definition'] | |
return f"According To The Nasa : {retur}" | |
else: | |
return "No Data Available , Try Again Later!" | |
def MarsImage(Api_Key,PathNow,PathToSave): | |
name = 'curiosity' | |
date = '2020-12-3' | |
Api_ = str(Api_Key) | |
url = f"https://api.nasa.gov/mars-photos/api/v1/rovers/{name}/photos?earth_date={date}&api_key={Api_}" | |
r = requests.get(url) | |
Data = r.json() | |
Photos = Data['photos'][:20] | |
try: | |
for index , photo in enumerate(Photos): | |
camera = photo['camera'] | |
rover = photo['rover'] | |
full_camera_name = camera['full_name'] | |
date_of_photo = photo['earth_date'] | |
img_url = photo['img_src'] | |
p = requests.get(img_url) | |
img = f'{index}.jpg' | |
with open(img,'wb') as file: | |
file.write(p.content) | |
Path_1 = str(PathNow) + str(img) | |
Path_2 = str(PathToSave) + str(img) | |
os.rename(Path_1,Path_2) | |
os.startfile(Path_2) | |
return f''' | |
This Image Was Captured With : {full_camera_name} | |
"This Image Was Captured On : {date_of_photo}''' | |
except: | |
return "There IS An Error!" | |
def IssTracker(): | |
url = "http://api.open-notify.org/iss-now.json" | |
r = requests.get(url) | |
Data = r.json() | |
dt = Data['timestamp'] | |
lat = Data['iss_position']['latitude'] | |
lon = Data['iss_position']['longitude'] | |
print(f"Time And Date : {dt}") | |
print(f"Latitude : {lat}") | |
print(f"Longitude : {lon}") | |
plt.figure(figsize=(10,8)) | |
ax = plt.axes(projection = ccrs.PlateCarree()) | |
ax.stock_img() | |
plt.scatter(float(lon),float(lat),color = 'blue' , marker= 'o') | |
plt.show() | |
def Astro(start_date,end_date,Api_Key): | |
url = f"https://api.nasa.gov/neo/rest/v1/feed?start_date={start_date}&end_date={end_date}&api_key={Api_Key}" | |
r = requests.get(url) | |
Data = r.json() | |
Total_Astro = Data['element_count'] | |
neo = Data['near_earth_objects'] | |
for body in neo[start_date]: | |
id = body['id'] | |
name = body['name'] | |
absolute = body['absolute_magnitude_h'] | |
print(id,name,absolute) | |
return f'''Total Astroid Between {start_date} and {end_date} Is : {Total_Astro}''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment