Skip to content

Instantly share code, notes, and snippets.

@maisieccino
Created July 29, 2018 13:26
Show Gist options
  • Save maisieccino/b20416daee04c322a203817517780ae8 to your computer and use it in GitHub Desktop.
Save maisieccino/b20416daee04c322a203817517780ae8 to your computer and use it in GitHub Desktop.
Finds empty maps and surveys using the UCL API
import requests, json
from os import environ
import sys
uclapi_token = environ.get("UCLAPI_TOKEN")
response = requests.get("https://uclapi.com/workspaces/surveys", params={"token":uclapi_token})
if not response.ok:
print("failed to get survey data", file=sys.stderr)
sys.exit(1)
surveys = response.json()['surveys']
def is_map_empty(sensor_map):
sensor_count = len(sensor_map['sensors'].keys())
return sensor_count == 0
def get_empty_maps(survey):
survey_id = survey['id']
res = requests.get("https://uclapi.com/workspaces/sensors", params={
"token": uclapi_token,
"survey_id": survey_id
})
if not res.ok:
print("failed to get data for survey {}".format(survey_id), file=sys.stderr)
sys.exit(1)
maps = res.json()["maps"]
if len(maps) == 0:
print("survey {} (id {}) has no maps!".format(survey["name"], survey_id))
return
empty_maps = list(filter(is_map_empty, maps))
if len(empty_maps) > 0:
print("survey {} (id {}) has empty maps!".format(survey["name"], survey_id))
for sensor_map in empty_maps:
print(" * {} (id {})".format(sensor_map["name"], sensor_map["id"]))
for survey in surveys:
get_empty_maps(survey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment