Skip to content

Commit 3120bf4

Browse files
v0.0.2
0 parents  commit 3120bf4

File tree

12 files changed

+449
-0
lines changed

12 files changed

+449
-0
lines changed

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Python Nasa API
2+
3+
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!
4+
5+
## Quick Docs
6+
7+
You need NASA's Official API to use this module!
8+
9+
### Load Client Class
10+
11+
```py
12+
# Import Client Class
13+
from nasaapi import Client
14+
15+
# Load your api
16+
nasa = Client(api)
17+
# Replace your api with the original one!
18+
```
19+
20+
### Apod
21+
22+
```py
23+
print(nasa.apod())
24+
# Will return a dict
25+
26+
print(nasa.apod_image())
27+
# Will retun apod image url
28+
```
29+
30+
### Earth
31+
32+
```py
33+
print(nasa.earth(lat, lon, date))
34+
# Lat Lon parameters should be latitude and longitude
35+
# Date parameter should be in the form of YYYY-MM-DD
36+
# Will return a dict
37+
38+
print(nasa.earth_image(lat, lon, date))
39+
# Will return image url
40+
```
41+
42+
### Insight Weather Data
43+
44+
```py
45+
print(nasa.insight())
46+
# Will return a dict
47+
```
48+
49+
### Data of mars rovers
50+
51+
There are two methods to get this data
52+
53+
**1. Using MarsRovers Class**
54+
55+
```py
56+
from nasaapi import MarsRovers
57+
58+
rovers = MarsRovers(api_key, sols, camera)
59+
# api_key would be your NASA Api key. Sols would be the Mars Days. Camera is the name of camera to view
60+
61+
print(rovers.curiosity()) # Get data of Curiosity Rover
62+
print(rovers.opportunity()) # Get data of Oportunity Rover
63+
print(rovers.spirit()) # Get data of Spirit Rover
64+
```
65+
66+
**2. Using Client Class**
67+
68+
```py
69+
rovers = nasa.mars_rovers(sols, camera)
70+
# Sols would be the Mars Days. Camera is the name of camera to view
71+
72+
print(rovers.curiosity()) # Get data of Curiosity Rover
73+
print(rovers.opportunity()) # Get data of Oportunity Rover
74+
print(rovers.spirit()) # Get data of Spirit Rover
75+
```
76+
77+
### Techport
78+
79+
Get data of nasa's techport
80+
81+
```py
82+
print(nasa.techport(id))
83+
# ID will be the id of the techport project!
84+
# Will return dict unless its a better id
85+
```
86+
87+
### Two Line Element Sets of Nasa
88+
89+
Get data of nasa's tle
90+
91+
```py
92+
print(nasa.tle.search(query))
93+
# Will return data of a search
94+
95+
print(nasa.tle.get(query))
96+
# Will get of 1 data only
97+
```
98+
99+
### NIVL aka Nasa Image and Video Library
100+
101+
Get images, Search Images, and other image and video library of NASA
102+
103+
```py
104+
print(nasa.nivl.search(query))
105+
# Query will be the query you will search
106+
107+
print(nasa.nivl.asset(id))
108+
# Get Asset by ID
109+
110+
print(nasa.nivl.metadata(id))
111+
# Get Metadata by ID
112+
113+
print(nasa.nivl.captions(id))
114+
# Get Captions by ID
115+
```
116+
117+
## Support
118+
119+
- [Discord Support Server](https://discord.gg/FrduEZd)
120+
- [GitHub Repo](https://github.com/Scientific-Guy/python-nasa-api)

build/lib/nasaapi/__init__.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from json import loads as load
2+
from random import randint as random
3+
import requests
4+
5+
__version__ = '0.0.2'
6+
7+
class MarsRovers():
8+
9+
def __init__(self, api_key, sols=random(0, 2000), camera="fhaz"):
10+
self.api_key = api_key
11+
self.sols = str(sols)
12+
self.camera = str(camera)
13+
14+
def curiosity(self):
15+
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)
16+
17+
def spirit(self):
18+
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)
19+
20+
def opportunity(self):
21+
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)
22+
23+
class NIVL():
24+
25+
def __init__(self, api_key):
26+
self.api_key = api_key
27+
self.base = 'https://images-api.nasa.gov/'
28+
29+
def search(self, query):
30+
return load(requests.get(self.base + 'search?q=' + query).text)
31+
32+
def asset(self, id):
33+
return load(requests.get(self.base + 'asset/' + id).text)
34+
35+
def metadata(self, id):
36+
return load(requests.get(self.base + 'metadata/' + id).text)
37+
38+
def captions(self, id):
39+
return load(requests.get(self.base + 'captions/' + id).text)
40+
41+
class TLE():
42+
43+
def search(self, query):
44+
return load(requests.get('https://data.ivanstanojevic.me/api/tle?search=' + query).text)
45+
46+
def get(self, query):
47+
return load(requests.get('http://data.ivanstanojevic.me/api/tle/' + query).text)
48+
49+
class Client():
50+
51+
def __init__(self, api_key):
52+
self.api_key = api_key
53+
self.tle = TLE()
54+
self.nivl = NIVL(self.api_key)
55+
56+
def apod(self):
57+
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text)
58+
59+
def apod_image(self):
60+
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text).url
61+
62+
def earth(self, lat, lon, date):
63+
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)
64+
65+
def earth_image(self, lat, lon, date):
66+
try:
67+
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
68+
except:
69+
return None
70+
71+
def insight(self):
72+
return load(requests.get('https://api.nasa.gov/insight_weather/?api_key=' + self.api_key + '&feedtype=json&ver=1.0').text)
73+
74+
def mars_rovers(self, sols=random(0, 2000), camera="fhaz"):
75+
return MarsRovers(self.api_key, sols, camera)
76+
77+
def techport(self, id):
78+
try:
79+
return load(requests.get('https://api.nasa.gov/techport/api/projects/' + id + '?api_key=' + self.api_key).text)
80+
except:
81+
return 'invalid id'

dist/python-nasa-api-0.0.2.tar.gz

2.83 KB
Binary file not shown.
2.93 KB
Binary file not shown.

nasaapi/__init__.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from json import loads as load
2+
from random import randint as random
3+
import requests
4+
5+
__version__ = '0.0.2'
6+
7+
class MarsRovers():
8+
9+
def __init__(self, api_key, sols=random(0, 2000), camera="fhaz"):
10+
self.api_key = api_key
11+
self.sols = str(sols)
12+
self.camera = str(camera)
13+
14+
def curiosity(self):
15+
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)
16+
17+
def spirit(self):
18+
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)
19+
20+
def opportunity(self):
21+
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)
22+
23+
class NIVL():
24+
25+
def __init__(self, api_key):
26+
self.api_key = api_key
27+
self.base = 'https://images-api.nasa.gov/'
28+
29+
def search(self, query):
30+
return load(requests.get(self.base + 'search?q=' + query).text)
31+
32+
def asset(self, id):
33+
return load(requests.get(self.base + 'asset/' + id).text)
34+
35+
def metadata(self, id):
36+
return load(requests.get(self.base + 'metadata/' + id).text)
37+
38+
def captions(self, id):
39+
return load(requests.get(self.base + 'captions/' + id).text)
40+
41+
class TLE():
42+
43+
def search(self, query):
44+
return load(requests.get('https://data.ivanstanojevic.me/api/tle?search=' + query).text)
45+
46+
def get(self, query):
47+
return load(requests.get('http://data.ivanstanojevic.me/api/tle/' + query).text)
48+
49+
class Client():
50+
51+
def __init__(self, api_key):
52+
self.api_key = api_key
53+
self.tle = TLE()
54+
self.nivl = NIVL(self.api_key)
55+
56+
def apod(self):
57+
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text)
58+
59+
def apod_image(self):
60+
return load(requests.get('https://api.nasa.gov/planetary/apod?api_key=' + self.api_key).text).url
61+
62+
def earth(self, lat, lon, date):
63+
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)
64+
65+
def earth_image(self, lat, lon, date):
66+
try:
67+
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
68+
except:
69+
return None
70+
71+
def insight(self):
72+
return load(requests.get('https://api.nasa.gov/insight_weather/?api_key=' + self.api_key + '&feedtype=json&ver=1.0').text)
73+
74+
def mars_rovers(self, sols=random(0, 2000), camera="fhaz"):
75+
return MarsRovers(self.api_key, sols, camera)
76+
77+
def techport(self, id):
78+
try:
79+
return load(requests.get('https://api.nasa.gov/techport/api/projects/' + id + '?api_key=' + self.api_key).text)
80+
except:
81+
return 'invalid id'
5.25 KB
Binary file not shown.

0 commit comments

Comments
 (0)