Skip to end of metadata
Go to start of metadata

During the Zermelo Symposium one of the talks was "Getting started with the API". The presentation itself was in Dutch.

This is the Python script that we wrote during the presentation:

schedule.py
import requests
# Retrieve the portal status message
endpoint = "https://apidemo.zportal.nl/api/v3/"
status = requests.get(endpoint + "status/status_message").text
print("Portal status: " + status)
# Retrieve appointments
# print(requests.get(endpoint + "appointments?user=~me").json()) # gives HTTP 401
token = "so7k8ma73qj7ndropa5tgc0h46"
user = "wes"

# Again, now with the token
# print(requests.get(endpoint + "appointments?user="+user+"&access_token="+token).json())
 
# This is way too much (all appointments for the entire year). We need to restrict to a certain time.
import time
import datetime
datum_start = "06/1/2015"
datum_stop = "07/1/2015"
timestamp_start = time.mktime(datetime.datetime.strptime(datum_start, "%d/%m/%Y").timetuple())
timestamp_end = time.mktime(datetime.datetime.strptime(datum_stop, "%d/%m/%Y").timetuple())
 
json_response = requests.get(endpoint + "appointments?user="+user+"&access_token="+token+"&start="+str(int(timestamp_start))+"&end="+str(int(timestamp_end))+"&valid=true").json()
# print(json_response)
appointments = json_response['response']['data']
# we need to sort them
def start_field(appointment):
    return int(appointment['start'])
appointments.sort(key=start_field)
# now print them
def time_string(timestamp):
    return datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S')
     
for appointment in appointments:
    print(time_string(appointment['start'])+" "+str(appointment['startTimeSlot'])+" "+",".join(appointment['teachers']) + " " + ','.join(appointment['subjects']) + " " + ','.join(appointment['locations']))
  • No labels