scdl/scdl/client.py

30 lines
844 B
Python
Raw Normal View History

2015-05-14 00:45:02 -07:00
# -*- encoding: utf-8 -*-
import requests
from scdl import CLIENT_ID, USER_AGENT
class Client():
def get_collection(self, url, token):
2016-09-27 11:06:15 -07:00
params = {
'client_id': CLIENT_ID,
'linked_partitioning': '1',
}
if token:
params['oauth_token'] = token
resources = list()
2016-01-31 05:16:20 -08:00
while url:
response = requests.get(url, params=params, headers={'User-Agent': USER_AGENT})
response.raise_for_status()
json_data = response.json()
if 'collection' in json_data:
resources.extend(json_data['collection'])
else:
resources.extend(json_data)
if 'next_href' in json_data:
url = json_data['next_href']
else:
2016-01-31 05:16:20 -08:00
url = None
return resources