from memair import Memair
import collections
# Use Otto the sandbox user's access token or create your own at https://memair.com/temporary_access_token
access_token = '0000000000000000000000000000000000000000000000000000000000000000'
user = Memair(access_token)
first_page_query = '''
{
Locations(
first: 5
order_by: timestamp
order: asc
) {
id
lat
lon
}
}
'''
first_page = user.query(first_page_query)['data']['Locations']
# Extract last id of page for use in next page
last_id_of_first_page = first_page[-1]['id']
second_page_query = '''
{
Locations(
first: 5
order_by: timestamp
order: asc
after: %s
) {
id
lat
lon
}
}
''' % last_id_of_first_page # setting last id of previous page as the after argument
second_page = user.query(second_page_query)['data']['Locations']
# Total locations returned
locations = first_page + second_page
len(locations)
10
# Ensure collected locations are unique
collections.Counter(location['id'] for location in locations)
Counter({'42884351': 1, '42986348': 1, '42884366': 1, '42986347': 1, '42986346': 1, '42986345': 1, '42986344': 1, '42986343': 1, '42986342': 1, '42986341': 1})