Created
July 21, 2017 12:24
-
-
Save anhiga/6297e9bf63c500fe05f71ce776aa8162 to your computer and use it in GitHub Desktop.
Poliastro files
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
''' | |
Module for retrieving info from NASA NeoWS API. | |
''' | |
import json | |
import requests | |
url = 'https://api.nasa.gov/neo/rest/v1/neo/' | |
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) \ | |
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} | |
payload = {'api_key' : 'DEMO_KEY'} | |
asteroid_id = input("What are you searching? ") | |
try: | |
response = requests.get(url + asteroid_id, params=payload, headers=headers) | |
if response.status_code == 200: | |
parsed = json.loads(response.text) | |
elif response.status_code == 404: | |
print("\nObject ID does not exists, or it is not a NEO asteroid.") | |
else: | |
print('\nForbidden or unauthorized request: ', response.status_code) | |
except requests.exceptions.RequestException: | |
print('\nSome kind of connection error ocurred, please try later.') | |
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
''' | |
Module for, given a small body object name, retrieving info from | |
JPL Small-Body Database, such as SPK-ID, classification and complete name | |
''' | |
import re | |
import html | |
import requests | |
from bs4 import BeautifulSoup | |
url = 'https://ssd.jpl.nasa.gov/sbdb.cgi' | |
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) \ | |
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} | |
object_req = input("What are you searching? ") | |
payload = {'sstr' : object_req, 'orb' : '0', 'log' : '0', 'old' : '0', 'cov' : '0', 'cad' : '0'} | |
try: | |
response = requests.get(url, params=payload, headers=headers) | |
soup = BeautifulSoup(response.text, "html.parser") | |
info = soup.find(attrs={"name": "top"}).find_next_sibling('table').table.find_all('td') | |
if info: | |
object_name = info[0].string | |
print(object_name) | |
string_oneline = '' | |
for string in info[1].stripped_strings: | |
string_oneline += string + ' ' | |
print(string_oneline) | |
regex = re.compile("Classification: ([\w\s|\[\s|\]\s]+)SPK-ID: (\d+)") | |
print(regex.match(string_oneline).groups()) | |
else: | |
print('Object could not be founded. You can visit: ',\ | |
url + "?sstr=" + object_req, " for more information.") | |
epochs = soup.find(attrs={"name": "elem"}).next_sibling.find_all('option') | |
if epochs: | |
print('\nThe following alternate orbits are available:') | |
print('\n---------------------------------------------\n') | |
for epoch in epochs: | |
print(epoch.string) | |
print('\n---------------------------------------------\n') | |
epoch=input("Choose one [default]: ") | |
payload = {'soln' : epoch, 'cov' : '0', 'cad' : '0', 'sstr' : object,\ | |
'orb' : '0', 'log' : '0', 'old' : '0'} | |
response = requests.get(url, params=payload, headers=headers) | |
soup = BeautifulSoup(response.text, "lxml") | |
except requests.exceptions.RequestException: | |
print('Some kind of connection error ocurred, please try later.') | |
# except AttributeError: | |
# print('Object could not be founded. You can visit: ',\ | |
# url + "?sstr=" + object_req, " for more information.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment