1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import requests
- ConnectionError = requests.exceptions.ConnectionError
- class Client:
- base_url = 'https://api.audiovalid.com'
- def __init__(self, key, secret, base_url=None):
- self.key = key
- self.secret = secret
- if base_url:
- self.base_url = base_url
- @property
- def headers(self):
- return {
- 'Authorization': '{} {}'\
- .format(self.key, self.secret)
- }
- def put_schedule_results(self, sched_id, item_id,
- results, found=None,
- missing_files=0):
- url = '{}/schedule/{}/item/{}/results'.format(
- self.base_url,
- sched_id,
- item_id,
- )
- response = requests.put(url,
- json={
- 'results': results,
- 'found': found,
- 'missing_files': missing_files \
- if missing_files is not None
- else 0,
- },
- headers=self.headers,
- )
- return response.json()
- def get_schedule_pending(self):
- url = '{}/schedule/pending'.format(self.base_url)
- response = requests.get(url, headers=self.headers)
- return response.json()
- def get_channels(self):
- """ Return the list of TV channels """
- url = '{}/channel'.format(self.base_url)
- response = requests.get(url, headers=self.headers)
- return response.json()['channels']
- def get_calibrations(self, station=None):
- """ Return the calibration of a station in a box """
- url = '{}/device'.format(self.base_url)
- params = {'what': 'calibrations'}
- if station:
- params['station'] = station
- response = requests.get(url,
- headers=self.headers,
- params=params,
- )
- return response.json()['calibrations']
|