download_from_api_tellus

Download from the Tellus API from data.amsterdam.nl using the OAuth2 datapunt Authorization service. Command line example:

download_from_api_tellus https://api.data.amsterdam.nl/tellus data tellusdata.csv 10

usage: download_from_api_tellus [-h] url output_folder filename limit

Positional Arguments

url add full endpoint, for example https://api.data.amsterdam.nl/tellus/
output_folder add outputfolder location, for example my_project_folder/data or . if you want to save in the current dir
filename add filename for example tellusdata.csv
limit add limited number of pages to test outputfile

functions

datapunt_processing.extract.download_from_api_tellus.conversionListCvalues(metadata)

Create a conversion dictionairy for values in tellus api which consists of 60 speed +length values named: c1 to c60

datapunt_processing.extract.download_from_api_tellus.getJsonData(url, accessToken)

Get a json response from a url with accesstoken.

Args:
  1. url: api endpoint
  2. accessToken: acces token generated using the auth helper: GetAccessToken().getAccessToken(usertype=’employee’, scopes=’TLLS/R’)
Returns:
parsed json or error message
datapunt_processing.extract.download_from_api_tellus.get_data(url_api, endpoint, metadata, accessToken, limit)

Get and flatten all the data from the api.

Args:
  1. url_api: get the main api url:

    https://api.data.amsterdam.nl/tellus
    
  2. get one endpoint:

    tellus
    
  3. get a list of dictionaries from other endpoints, in this case: for tellus location, speed and length.

  4. accessToken: acces token generated using the auth helper: GetAccessToken().getAccessToken()

  5. limit: set the number of pages you want to retrieve, ideal for testing first:

    10

Returns:
A list containing multiple items which are all reformatted to a flattened json with added metadata.
datapunt_processing.extract.download_from_api_tellus.parser()

Parser function to run arguments from commandline and to add description to sphinx docs.

datapunt_processing.extract.download_from_api_tellus.reformatData(item, tellus_metadata, cvalues)

Reformat the data from a matrix to a flattend dict with label and tellus names.

Args:
  1. item: one recorded hour which contains 60 types of registrations c1-c60.
  2. tellus_metadata: list of description values for each tellus.
  3. cvalues: converted 60 values to add the proper labels to c1 to c6 counted record.
Returns:
60 rows by c-value with metadata an label descriptions