Skip to content

Instantly share code, notes, and snippets.

@chrisoldwood
Created June 2, 2018 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisoldwood/010f22df994897c738ce4bdc1c47f84a to your computer and use it in GitHub Desktop.
Save chrisoldwood/010f22df994897c738ce4bdc1c47f84a to your computer and use it in GitHub Desktop.
Python script to query the Fixr REST API
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])
@chrisoldwood
Copy link
Author

chrisoldwood commented Jun 2, 2018

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 and name properties of the venue or event, e.g.

> python fixr.py list-venues | head -n 3
2974: 39 Gordon Street
 163: Amusement 13
3138: Bal Fashions
> python fixr.py list-events --venue-id 1261
 937743295: Propaganda Norwich - Festival Kit Giveaway
 338528003: Propaganda Norwich - Jurassic Party

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment