diff --git a/README.md b/README.md new file mode 100644 index 0000000..86bc7d0 --- /dev/null +++ b/README.md @@ -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) \ No newline at end of file diff --git a/build/lib/nasaapi/__init__.py b/build/lib/nasaapi/__init__.py new file mode 100644 index 0000000..545b9d4 --- /dev/null +++ b/build/lib/nasaapi/__init__.py @@ -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' \ No newline at end of file diff --git a/dist/python-nasa-api-0.0.2.tar.gz b/dist/python-nasa-api-0.0.2.tar.gz new file mode 100644 index 0000000..78533f2 Binary files /dev/null and b/dist/python-nasa-api-0.0.2.tar.gz differ diff --git a/dist/python_nasa_api-0.0.2-py3-none-any.whl b/dist/python_nasa_api-0.0.2-py3-none-any.whl new file mode 100644 index 0000000..9f81936 Binary files /dev/null and b/dist/python_nasa_api-0.0.2-py3-none-any.whl differ diff --git a/nasaapi/__init__.py b/nasaapi/__init__.py new file mode 100644 index 0000000..545b9d4 --- /dev/null +++ b/nasaapi/__init__.py @@ -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' \ No newline at end of file diff --git a/nasaapi/__pycache__/__init__.cpython-35.pyc b/nasaapi/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..f843c2a Binary files /dev/null and b/nasaapi/__pycache__/__init__.cpython-35.pyc differ diff --git a/python_nasa_api.egg-info/PKG-INFO b/python_nasa_api.egg-info/PKG-INFO new file mode 100644 index 0000000..05faa40 --- /dev/null +++ b/python_nasa_api.egg-info/PKG-INFO @@ -0,0 +1,132 @@ +Metadata-Version: 2.1 +Name: python-nasa-api +Version: 0.0.2 +Summary: Simple NASA Api Wrapper written in Python! +Home-page: UNKNOWN +License: MIT +Description: # 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) +Keywords: python-nasa-api +Platform: UNKNOWN +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.7 +Description-Content-Type: text/markdown diff --git a/python_nasa_api.egg-info/SOURCES.txt b/python_nasa_api.egg-info/SOURCES.txt new file mode 100644 index 0000000..d9076ca --- /dev/null +++ b/python_nasa_api.egg-info/SOURCES.txt @@ -0,0 +1,8 @@ +README.md +setup.cfg +setup.py +nasaapi/__init__.py +python_nasa_api.egg-info/PKG-INFO +python_nasa_api.egg-info/SOURCES.txt +python_nasa_api.egg-info/dependency_links.txt +python_nasa_api.egg-info/top_level.txt \ No newline at end of file diff --git a/python_nasa_api.egg-info/dependency_links.txt b/python_nasa_api.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/python_nasa_api.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/python_nasa_api.egg-info/top_level.txt b/python_nasa_api.egg-info/top_level.txt new file mode 100644 index 0000000..a7daaf6 --- /dev/null +++ b/python_nasa_api.egg-info/top_level.txt @@ -0,0 +1 @@ +nasaapi diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..badc95f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +# Inside of setup.cfg +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c0a254a --- /dev/null +++ b/setup.py @@ -0,0 +1,22 @@ +from setuptools import setup + +def readme(): + with open('README.md') as f: + README = f.read() + return README + +setup( + name="python-nasa-api", + version="0.0.2", + description="Simple NASA Api Wrapper written in Python!", + long_description=readme(), + long_description_content_type="text/markdown", + packages=['nasaapi'], + keywords="python-nasa-api", + classifiers=[ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + ], + license="MIT", +) \ No newline at end of file