Code cleanup.

This commit is contained in:
RecursiveGreen 2019-06-05 15:28:35 -04:00
parent 32ef9afae3
commit 789d58f1b9

View file

@ -68,11 +68,9 @@ def next_request():
''' '''
LOGGER.debug('Received command to get next song request.') LOGGER.debug('Received command to get next song request.')
try: try:
r = requests.get(API_URL + 'next/', resp = requests.get(API_URL + 'next/', headers=HEADERS, timeout=5)
headers=HEADERS, resp.encoding = 'utf-8'
timeout=5) resp.raise_for_status()
r.encoding = 'utf-8'
r.raise_for_status()
except requests.exceptions.HTTPError as errh: except requests.exceptions.HTTPError as errh:
LOGGER.error('Http Error: %s', errh) LOGGER.error('Http Error: %s', errh)
except requests.exceptions.ConnectionError as errc: except requests.exceptions.ConnectionError as errc:
@ -82,9 +80,9 @@ def next_request():
except requests.exceptions.RequestException as err: except requests.exceptions.RequestException as err:
LOGGER.error('Error: %s', err) LOGGER.error('Error: %s', err)
else: else:
LOGGER.debug('Received JSON response: %s', r.text) LOGGER.debug('Received JSON response: %s', resp.text)
req = json.loads(r.text) song_request = json.loads(resp.text)
song = req['song'] song = song_request['song']
if song['song_type'] == 'J': if song['song_type'] == 'J':
artist = RADIO_NAME artist = RADIO_NAME
title = 'Jingle' title = 'Jingle'
@ -95,14 +93,14 @@ def next_request():
game = clean_quotes(song['game']) game = clean_quotes(song['game'])
LOGGER.info( LOGGER.info(
'Req_ID: %s, Artist[s]: %s, Title: %s, Game: %s, Path: %s', 'Req_ID: %s, Artist[s]: %s, Title: %s, Game: %s, Path: %s',
req['id'], song_request['id'],
artist, artist,
title, title,
game, game,
song['path'] song['path']
) )
annotate_string = ANNOTATE.format( annotate_string = ANNOTATE.format(
req['id'], song_request['id'],
song['song_type'], song['song_type'],
artist, artist,
title, title,
@ -120,13 +118,15 @@ def just_played(request_id):
''' '''
LOGGER.debug('Received command to report a song was just played.') LOGGER.debug('Received command to report a song was just played.')
try: try:
req_played = json.dumps({'song_request': request_id}) request_played = json.dumps({'song_request': request_id})
r = requests.post(API_URL + 'played/', resp = requests.post(
API_URL + 'played/',
headers=HEADERS, headers=HEADERS,
data=req_played, data=request_played,
timeout=5) timeout=5
r.encoding = 'utf-8' )
r.raise_for_status() resp.encoding = 'utf-8'
resp.raise_for_status()
except requests.exceptions.HTTPError as errh: except requests.exceptions.HTTPError as errh:
LOGGER.error('Http Error: %s', errh) LOGGER.error('Http Error: %s', errh)
except requests.exceptions.ConnectionError as errc: except requests.exceptions.ConnectionError as errc: