Created
June 2, 2018 23:19
-
-
Save chrisoldwood/010f22df994897c738ce4bdc1c47f84a to your computer and use it in GitHub Desktop.
Python script to query the Fixr REST API
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
import requests | |
import argparse | |
import sys | |
def listVenues(): | |
response = requests.get(f'{baseUrl}/venue?limit=1000&offset=0') | |
json = response.json() | |
for venue in json['data']: | |
id = venue['id'] | |
name = venue['name'] | |
print(f'{id:4}: {name}') | |
def listEvents(venueId): | |
response = requests.get(f'{baseUrl}/venue/{venueId}') | |
json = response.json() | |
for event in json['events']: | |
id = event['id'] | |
name = event['name'] | |
print(f'{id:10}: {name}') | |
parser = argparse.ArgumentParser(description = 'Fixr API query tool') | |
parser.add_argument('verb', choices = ['list-venues', 'list-events'], help = 'Verb to execute') | |
parser.add_argument('--venue-id', nargs = 1, help = 'The ID of the venue') | |
args = parser.parse_args() | |
hostname = 'api.fixr-app.com' | |
baseUrl = f'https://{hostname}/api/v2/app' | |
if (args.verb == 'list-venues'): | |
listVenues() | |
if (args.verb == 'list-events'): | |
if ( (type(args.venue_id) is not list) or (len(args.venue_id) != 1) ): | |
parser.print_help() | |
sys.exit(1) | |
listEvents(args.venue_id[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is a simple CLI for the Fixr REST API. Currently it only supports a few verbs:
list-venues
list-events --venue-id <id>
It currently only dumps the
id
andname
properties of the venue or event, e.g.