Access for researchers
Getting access to the public posts data requires api key as well as additional permissions (could be requested by contacting our support team)
Public posts data API is identical to the Posts API, but you have to use special endpoints endpoints
Examples
Retrieving post list for researchers
import os
import json
import requests
api_url = 'https://mycityair.ru/harvester/v2/publicposts'
api_key = os.getenv('CITYAIR_TOKEN') # or set your api key directly
assert api_key, 'API key is empty'
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}',
}
response = requests.get(api_url, headers=headers)
response.raise_for_status()
formatted_response = json.dumps(response.json(), indent=2, ensure_ascii=False)
print(formatted_response)
Retrieving data from the post list for researchers
import datetime
import json
import os
import requests
public_post_list_url = 'https://mycityair.ru/harvester/v2/publicposts'
api_key = os.getenv('CITYAIR_TOKEN') # or set your api key directly
assert api_key, 'API key is empty'
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}',
}
response = requests.get(public_post_list_url, headers=headers)
response.raise_for_status()
posts = response.json()
assert len(posts) > 0, 'At least one post is required'
post = posts[0]
print(f'Got public post {post["id"]}:{post["name"]}')
interval = '1h'
date_start = (datetime.datetime.utcnow() - datetime.timedelta(days=1)).isoformat()
post_measurements_url = f'https://mycityair.ru/harvester/v2/publicposts/measurements?ids={post["id"]}&' \
f'interval={interval}&' \
f'date__gt={date_start}'
response = requests.get(post_measurements_url, headers=headers)
assert response.status_code == 200, f'Server responded with error: {response.text}'
response.raise_for_status()
formatted_response = json.dumps(response.json(), indent=2, ensure_ascii=False)
print(formatted_response)