-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3120bf4
Showing
12 changed files
with
449 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Python Nasa API | ||
|
||
Simple wrapper for NASA Api written in python which was previously written by abh80 in **Javascript** as NPM which is deprecated now so i aka Science Spot recreated it in **Python** using requests modules! | ||
|
||
## Quick Docs | ||
|
||
You need NASA's Official API to use this module! | ||
|
||
### Load Client Class | ||
|
||
```py | ||
# Import Client Class | ||
from nasaapi import Client | ||
|
||
# Load your api | ||
nasa = Client(api) | ||
# Replace your api with the original one! | ||
``` | ||
|
||
### Apod | ||
|
||
```py | ||
print(nasa.apod()) | ||
# Will return a dict | ||
|
||
print(nasa.apod_image()) | ||
# Will retun apod image url | ||
``` | ||
|
||
### Earth | ||
|
||
```py | ||
print(nasa.earth(lat, lon, date)) | ||
# Lat Lon parameters should be latitude and longitude | ||
# Date parameter should be in the form of YYYY-MM-DD | ||
# Will return a dict | ||
|
||
print(nasa.earth_image(lat, lon, date)) | ||
# Will return image url | ||
``` | ||
|
||
### Insight Weather Data | ||
|
||
```py | ||
print(nasa.insight()) | ||
# Will return a dict | ||
``` | ||
|
||
### Data of mars rovers | ||
|
||
There are two methods to get this data | ||
|
||
**1. Using MarsRovers Class** | ||
|
||
```py | ||
from nasaapi import MarsRovers | ||
|
||
rovers = MarsRovers(api_key, sols, camera) | ||
# api_key would be your NASA Api key. Sols would be the Mars Days. Camera is the name of camera to view | ||
|
||
print(rovers.curiosity()) # Get data of Curiosity Rover | ||
print(rovers.opportunity()) # Get data of Oportunity Rover | ||
print(rovers.spirit()) # Get data of Spirit Rover | ||
``` | ||
|
||
**2. Using Client Class** | ||
|
||
```py | ||
rovers = nasa.mars_rovers(sols, camera) | ||
# Sols would be the Mars Days. Camera is the name of camera to view | ||
|
||
print(rovers.curiosity()) # Get data of Curiosity Rover | ||
print(rovers.opportunity()) # Get data of Oportunity Rover | ||
print(rovers.spirit()) # Get data of Spirit Rover | ||
``` | ||
|
||
### Techport | ||
|
||
Get data of nasa's techport | ||
|
||
```py | ||
print(nasa.techport(id)) | ||
# ID will be the id of the techport project! | ||
# Will return dict unless its a better id | ||
``` | ||
|
||
### Two Line Element Sets of Nasa | ||
|
||
Get data of nasa's tle | ||
|
||
```py | ||
print(nasa.tle.search(query)) | ||
# Will return data of a search | ||
|
||
print(nasa.tle.get(query)) | ||
# Will get of 1 data only | ||
``` | ||
|
||
### NIVL aka Nasa Image and Video Library | ||
|
||
Get images, Search Images, and other image and video library of NASA | ||
|
||
```py | ||
print(nasa.nivl.search(query)) | ||
# Query will be the query you will search | ||
|
||
print(nasa.nivl.asset(id)) | ||
# Get Asset by ID | ||
|
||
print(nasa.nivl.metadata(id)) | ||
# Get Metadata by ID | ||
|
||
print(nasa.nivl.captions(id)) | ||
# Get Captions by ID | ||
``` | ||
|
||
## Support | ||
|
||
- [Discord Support Server](https://discord.gg/FrduEZd) | ||
- [GitHub Repo](https://github.com/Scientific-Guy/python-nasa-api) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from json import loads as load | ||
from random import randint as random | ||
import requests | ||
|
||
__version__ = '0.0.2' | ||
|
||
class MarsRovers(): | ||
|
||
def __init__(self, api_key, sols=random(0, 2000), camera="fhaz"): | ||
self.api_key = api_key | ||
self.sols = str(sols) | ||
self.camera = str(camera) | ||
|
||
def curiosity(self): | ||
return load(requests.get('https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=' + self.sols + '&camera=' + self.camera + '&api_key=' + self.api_key).text) | ||
|
||
def spirit(self): | ||
return load(requests.get('https://api.nasa.gov/mars-photos/api/v1/rovers/spirit/photos?sol=' + self.sols + '&camera=' + self.camera + '&api_key=' + self.api_key).text) | ||
|
||
def opportunity(self): | ||
return load(requests.get('https://api.nasa.gov/mars-photos/api/v1/rovers/opportunity/photos?sol=' + self.sols + '&camera=' + self.camera + '&api_key=' + self.api_key).text) | ||
|
||
class NIVL(): | ||
|
||
def __init__(self, api_key): | ||
self.api_key = api_key | ||
self.base = 'https://images-api.nasa.gov/' | ||
|
||
def search(self, query): | ||
return load(requests.get(self.base + 'search?q=' + query).text) | ||
|
||
def asset(self, id): | ||
return load(requests.get(self.base + 'asset/' + id).text) | ||
|
||
def metadata(self, id): | ||
return load(requests.get(self.base + 'metadata/' + id).text) | ||
|
||
def captions(self, id): | ||
return load(requests.get(self.base + 'captions/' + id).text) | ||
|
||
class TLE(): | ||
|
||
def search(self, query): | ||
return load(requests.get('https://data.ivanstanojevic.me/api/tle?search=' + query).text) | ||
|
||
def get(self, query): | ||
return load(requests.get('http://data.ivanstanojevic.me/api/tle/' + query).text) | ||
|
||
class Client(): | ||
|
||
def __init__(self, api_key): | ||
self.api_key = api_key | ||
self.tle = TLE() | ||
self.nivl = NIVL(self.api_key) | ||
|
||
def apod(self): | ||
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text) | ||
|
||
def apod_image(self): | ||
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text).url | ||
|
||
def earth(self, lat, lon, date): | ||
return load(requests.get('https://api.nasa.gov/planetary/earth/assets?lon=' + str(lon) + '&lat=' + str(lat) + '&date=' + str(date) + '&&dim=0.10&api_key=' + self.api_key).text) | ||
|
||
def earth_image(self, lat, lon, date): | ||
try: | ||
load(requests.get('https://api.nasa.gov/planetary/earth/assets?lon=' + str(lon) + '&lat=' + str(lat) + '&date=' + str(date) + '&&dim=0.10&api_key=' + self.api_key).text).url | ||
except: | ||
return None | ||
|
||
def insight(self): | ||
return load(requests.get('https://api.nasa.gov/insight_weather/?api_key=' + self.api_key + '&feedtype=json&ver=1.0').text) | ||
|
||
def mars_rovers(self, sols=random(0, 2000), camera="fhaz"): | ||
return MarsRovers(self.api_key, sols, camera) | ||
|
||
def techport(self, id): | ||
try: | ||
return load(requests.get('https://api.nasa.gov/techport/api/projects/' + id + '?api_key=' + self.api_key).text) | ||
except: | ||
return 'invalid id' |
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from json import loads as load | ||
from random import randint as random | ||
import requests | ||
|
||
__version__ = '0.0.2' | ||
|
||
class MarsRovers(): | ||
|
||
def __init__(self, api_key, sols=random(0, 2000), camera="fhaz"): | ||
self.api_key = api_key | ||
self.sols = str(sols) | ||
self.camera = str(camera) | ||
|
||
def curiosity(self): | ||
return load(requests.get('https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=' + self.sols + '&camera=' + self.camera + '&api_key=' + self.api_key).text) | ||
|
||
def spirit(self): | ||
return load(requests.get('https://api.nasa.gov/mars-photos/api/v1/rovers/spirit/photos?sol=' + self.sols + '&camera=' + self.camera + '&api_key=' + self.api_key).text) | ||
|
||
def opportunity(self): | ||
return load(requests.get('https://api.nasa.gov/mars-photos/api/v1/rovers/opportunity/photos?sol=' + self.sols + '&camera=' + self.camera + '&api_key=' + self.api_key).text) | ||
|
||
class NIVL(): | ||
|
||
def __init__(self, api_key): | ||
self.api_key = api_key | ||
self.base = 'https://images-api.nasa.gov/' | ||
|
||
def search(self, query): | ||
return load(requests.get(self.base + 'search?q=' + query).text) | ||
|
||
def asset(self, id): | ||
return load(requests.get(self.base + 'asset/' + id).text) | ||
|
||
def metadata(self, id): | ||
return load(requests.get(self.base + 'metadata/' + id).text) | ||
|
||
def captions(self, id): | ||
return load(requests.get(self.base + 'captions/' + id).text) | ||
|
||
class TLE(): | ||
|
||
def search(self, query): | ||
return load(requests.get('https://data.ivanstanojevic.me/api/tle?search=' + query).text) | ||
|
||
def get(self, query): | ||
return load(requests.get('http://data.ivanstanojevic.me/api/tle/' + query).text) | ||
|
||
class Client(): | ||
|
||
def __init__(self, api_key): | ||
self.api_key = api_key | ||
self.tle = TLE() | ||
self.nivl = NIVL(self.api_key) | ||
|
||
def apod(self): | ||
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text) | ||
|
||
def apod_image(self): | ||
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text).url | ||
|
||
def earth(self, lat, lon, date): | ||
return load(requests.get('https://api.nasa.gov/planetary/earth/assets?lon=' + str(lon) + '&lat=' + str(lat) + '&date=' + str(date) + '&&dim=0.10&api_key=' + self.api_key).text) | ||
|
||
def earth_image(self, lat, lon, date): | ||
try: | ||
load(requests.get('https://api.nasa.gov/planetary/earth/assets?lon=' + str(lon) + '&lat=' + str(lat) + '&date=' + str(date) + '&&dim=0.10&api_key=' + self.api_key).text).url | ||
except: | ||
return None | ||
|
||
def insight(self): | ||
return load(requests.get('https://api.nasa.gov/insight_weather/?api_key=' + self.api_key + '&feedtype=json&ver=1.0').text) | ||
|
||
def mars_rovers(self, sols=random(0, 2000), camera="fhaz"): | ||
return MarsRovers(self.api_key, sols, camera) | ||
|
||
def techport(self, id): | ||
try: | ||
return load(requests.get('https://api.nasa.gov/techport/api/projects/' + id + '?api_key=' + self.api_key).text) | ||
except: | ||
return 'invalid id' |
Binary file not shown.
Oops, something went wrong.