Fix PEP8 issues

Some minor refactoring to follow PEP8 guidlines.
This commit is contained in:
Landon Abney 2018-06-16 20:13:25 -07:00
parent 578784a6f4
commit 36c2ddaaf6
No known key found for this signature in database
GPG Key ID: 15320D3C4A506996

View File

@ -31,7 +31,9 @@ Taultulli > Settings > Notification Agents > New Script > Script Arguments:
Select: Playback Start, Playback Pause Select: Playback Start, Playback Pause
Arguments: --jbop SELECTOR --userId {user_id} --username {username} Arguments: --jbop SELECTOR --userId {user_id} --username {username}
--sessionId {session_id} --killMessage Your message here. No quotes. --notify notifierID --sessionId {session_id}
--killMessage Your message here. No quotes.
--notify notifierID
Save Save
Close Close
@ -53,9 +55,10 @@ BODY_TEXT = "Killed {user}'s stream. Reason: {message}."
sess = requests.Session() sess = requests.Session()
# Ignore verifying the SSL certificate # Ignore verifying the SSL certificate
sess.verify = False # '/path/to/certfile' sess.verify = False # '/path/to/certfile'
# If verify is set to a path to a directory, # If verify is set to a path to a directory,
# the directory must have been processed using the c_rehash utility supplied with OpenSSL. # the directory must have been processed using the c_rehash utility supplied
# with OpenSSL.
SELECTOR = ['stream', 'allStreams'] SELECTOR = ['stream', 'allStreams']
@ -77,7 +80,8 @@ def send_notification(subject_text, body_text, notifier_id):
else: else:
raise Exception(response['response']['message']) raise Exception(response['response']['message'])
except Exception as e: except Exception as e:
sys.stderr.write("Tautulli API 'notify' request failed: {0}.".format(e)) sys.stderr.write(
"Tautulli API 'notify' request failed: {0}.".format(e))
return None return None
@ -87,15 +91,18 @@ def get_activity(user_id):
'cmd': 'get_activity'} 'cmd': 'get_activity'}
try: try:
req = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload) req = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2',
params=payload)
response = req.json() response = req.json()
res_data = response['response']['data']['sessions'] res_data = response['response']['data']['sessions']
user_streams = [d['session_id'] for d in res_data if d['user_id'] == user_id] user_streams = [d['session_id']
for d in res_data if d['user_id'] == user_id]
return user_streams return user_streams
except Exception as e: except Exception as e:
sys.stderr.write("Tautulli API 'get_activity' request failed: {0}.".format(e)) sys.stderr.write(
"Tautulli API 'get_activity' request failed: {0}.".format(e))
pass pass
@ -111,16 +118,19 @@ def terminate_session(session_id, message):
response = req.json() response = req.json()
if response['response']['result'] == 'success': if response['response']['result'] == 'success':
sys.stdout.write("Successfully killed Plex session: {0}.".format(session_id)) sys.stdout.write(
"Successfully killed Plex session: {0}.".format(session_id))
else: else:
raise Exception(response['response']['message']) raise Exception(response['response']['message'])
except Exception as e: except Exception as e:
sys.stderr.write("Tautulli API 'terminate_session' request failed: {0}.".format(e)) sys.stderr.write(
"Tautulli API 'terminate_session' request failed: {0}.".format(e))
return None return None
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Killing Plex streams from Tautulli.") parser = argparse.ArgumentParser(
description="Killing Plex streams from Tautulli.")
parser.add_argument('--jbop', required=True, choices=SELECTOR, parser.add_argument('--jbop', required=True, choices=SELECTOR,
help='Kill selector.\nChoices: (%(choices)s)') help='Kill selector.\nChoices: (%(choices)s)')
parser.add_argument('--userId', type=int, parser.add_argument('--userId', type=int,
@ -132,7 +142,8 @@ if __name__ == "__main__":
parser.add_argument('--killMessage', nargs='+', parser.add_argument('--killMessage', nargs='+',
help='Message to send to user whose stream is killed.') help='Message to send to user whose stream is killed.')
parser.add_argument('--notify', type=int, parser.add_argument('--notify', type=int,
help='Notification Agent ID number to Agent to send notification.') help='Notification Agent ID number to Agent to send ' +
'notification.')
opts = parser.parse_args() opts = parser.parse_args()