Compare commits

...

2 Commits

Author SHA1 Message Date
129e5ed16d
Ben doesn't understand f-strings 2019-04-21 20:34:06 +01:00
7d70a59cab
Add requests requirement 2019-04-21 20:28:45 +01:00
2 changed files with 11 additions and 11 deletions

View File

@ -31,36 +31,36 @@ class Jiffy:
def _check_media_exists(self, media_url): def _check_media_exists(self, media_url):
try: try:
logging.debug(f'Attempting to get file from "{media_url}".') logging.debug(f'Attempting to get file from {media_url}.')
resp = requests.get(media_url) resp = requests.get(media_url)
except Exception as e: except Exception as e:
logging.critical(f'An exception occurred: "{e}".') logging.critical(f'An exception occurred: {e}.')
return False return False
else: else:
media_check_status = resp.status_code if hasattr(resp, 'status_code') else None media_check_status = resp.status_code if hasattr(resp, 'status_code') else None
logging.debug(f'Received status code "{media_check_status}"') logging.debug(f'Received status code {media_check_status}')
return media_check_status == 200 return media_check_status == 200
def _load_file_from_url(self, media_url, duration=10): def _load_file_from_url(self, media_url, duration=10):
asset_upload_url = f'http://{self.host}/{self.api_url_v1_2}/assets' asset_upload_url = f'http://{self.host}/{self.api_url_v1_2}/assets'
data_to_upload = UPLOAD_IMAGE_JSON % (media_url, duration, media_url) data_to_upload = UPLOAD_IMAGE_JSON % (media_url, duration, media_url)
logging.debug(f'Attempting to upload "{media_url}" to "{asset_upload_url}".') logging.debug(f'Attempting to upload {media_url} to {asset_upload_url}.')
file_upload_response = requests.post(url=asset_upload_url, data=data_to_upload, auth=self.credentials) file_upload_response = requests.post(url=asset_upload_url, data=data_to_upload, auth=self.credentials)
file_upload_response_json = file_upload_response.json() file_upload_response_json = file_upload_response.json()
if not isinstance(file_upload_response_json, dict): if not isinstance(file_upload_response_json, dict):
logging.critical(f'Could not parse asset ID, received type "{type(file_upload_response_json)}"') logging.critical(f'Could not parse asset ID, received type {type(file_upload_response_json)}.')
return return
else: else:
asset_id = file_upload_response_json.get('asset_id') asset_id = file_upload_response_json.get('asset_id')
logging.debug(f'Received asset ID "{asset_id}"') logging.debug(f'Received asset ID {asset_id}.')
return asset_id return asset_id
def _display_asset(self, asset_id): def _display_asset(self, asset_id):
logging.debug(f'Attempting to display asset with ID "{asset_id}".') logging.debug(f'Attempting to display asset with ID {asset_id}.')
display_asset_response = requests.get( display_asset_response = requests.get(
f'http://{self.host}/{self.api_url_v1_0}/assets/control/asset&{asset_id}', f'http://{self.host}/{self.api_url_v1_0}/assets/control/asset&{asset_id}',
@ -70,19 +70,19 @@ class Jiffy:
display_asset_status_code = display_asset_response.status_code if getattr(display_asset_response, 'status_code') else None display_asset_status_code = display_asset_response.status_code if getattr(display_asset_response, 'status_code') else None
logging.debug( logging.debug(
f'Received status code of "{display_asset_status_code}" when trying to display asset with ID "{asset_id}".' f'Received status code of {display_asset_status_code} when trying to display asset with ID {asset_id}.'
) )
return display_asset_status_code == 200 return display_asset_status_code == 200
def _delete_asset(self, asset_id): def _delete_asset(self, asset_id):
logging.debug(f'Attempting to delete asset with ID "{asset_id}".') logging.debug(f'Attempting to delete asset with ID {asset_id}.')
delete_asset_response = requests.delete(f'http://{self.host}/{self.api_url_v1_2}/assets/{asset_id}', auth=self.credentials) delete_asset_response = requests.delete(f'http://{self.host}/{self.api_url_v1_2}/assets/{asset_id}', auth=self.credentials)
delete_asset_status_code = delete_asset_response.status_code if getattr(delete_asset_response, 'status_code') else None delete_asset_status_code = delete_asset_response.status_code if getattr(delete_asset_response, 'status_code') else None
logging.debug( logging.debug(
f'Received status code of "{delete_asset_status_code}", when trying to delete asset with ID "asset_id".' f'Received status code of {delete_asset_status_code}, when trying to delete asset with ID "asset_id".'
) )
return delete_asset_status_code return delete_asset_status_code

View File

@ -1,2 +1,2 @@
paho-mqtt==1.4.0 paho-mqtt==1.4.0
requests==2.18.4