Skip to content

Instantly share code, notes, and snippets.

@braised-babbage
Created December 28, 2019 19:35
Show Gist options
  • Save braised-babbage/dd6f81420bf8a868590c2e2868ee7edd to your computer and use it in GitHub Desktop.
Save braised-babbage/dd6f81420bf8a868590c2e2868ee7edd to your computer and use it in GitHub Desktop.
import requests
API_ENDPOINT = "https://psg.gsfc.nasa.gov/api.php"
EXAMPLE_CONFIG = "/Users/erik/Desktop/pspec/config.txt"
# NOTE: kwargs are explained here https://psg.gsfc.nasa.gov/helpapi.php
def get_spectra(config_path, **kwargs):
with open(config_path, 'r') as f:
kwargs['file'] = f.read()
r = requests.post(API_ENDPOINT, data=kwargs)
if r.status_code != requests.codes.ok:
raise ValueError(f"Error with HTTP response: {r.status_code}")
elif not r.text:
raise ValueError(f"Empty response from NASA server.")
else:
return r.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment