Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
add basic CLI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerdave committed Aug 22, 2016
1 parent 3628261 commit 67d9892
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bloomsky_api/bloomsky_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime
from dateutil import tz

from .exceptions import APIKeyMissing

DEFAULT_API_URL = 'https://thirdpartyapi.appspot.com/api/skydata/'


Expand Down Expand Up @@ -93,6 +95,8 @@ def __init__(self, api_key=None, api_url=None):
self.api_url = self._get_api_url(api_url)

def request_data(self):
if self.api_key is None:
raise APIKeyMissing("No API key provided. Set via env var or argument.")
headers = {'Authorization': self.api_key}
response = requests.get(self.api_url, headers=headers)
response.raise_for_status()
Expand Down
16 changes: 13 additions & 3 deletions bloomsky_api/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import click
import json

@click.command()
def cli():
click.echo("Hello, World!")
from .bloomsky_api import BloomSkyAPIClient

@click.command(help='Retrieve data from the BloomSky API and output it as JSON.')
@click.option('--api-key', envvar='BLOOMSKY_API_KEY',
help='BloomSky API key (can be set via env var BLOOMSKY_API_KEY).')
@click.option('--api-url', help='Override BloomSky API endpoint URL.')
@click.option('--json-indent', type=int, default=None,
help='Number of spaces to indent nested JSON levels.')
def cli(api_key, api_url, json_indent):
client = BloomSkyAPIClient(api_key=api_key, api_url=api_url)
data = client.get_data()
click.echo(json.dumps(data, indent=json_indent))

if __name__ == '__main__':
cli()

0 comments on commit 67d9892

Please sign in to comment.