Refactored pyponotify. Removed code duplication and made runner reusable by other scripts.
This commit is contained in:
parent
b0b2985529
commit
3b51c93766
1 changed files with 24 additions and 37 deletions
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import traceback
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Python part of radio playout (pypo)
|
Python part of radio playout (pypo)
|
||||||
|
@ -102,6 +103,24 @@ class Notify:
|
||||||
logger.debug('# Calling server to update webstream data #')
|
logger.debug('# Calling server to update webstream data #')
|
||||||
logger.debug('#################################################')
|
logger.debug('#################################################')
|
||||||
response = self.api_client.notify_webstream_data(data, media_id)
|
response = self.api_client.notify_webstream_data(data, media_id)
|
||||||
|
logger.debug("Response: " + json.dumps(response))
|
||||||
|
|
||||||
|
def run_with_options(self, options):
|
||||||
|
if options.error and options.stream_id:
|
||||||
|
self.notify_liquidsoap_status(options.error, options.stream_id, options.time)
|
||||||
|
elif options.connect and options.stream_id:
|
||||||
|
self.notify_liquidsoap_status("OK", options.stream_id, options.time)
|
||||||
|
elif options.source_name and options.source_status:
|
||||||
|
self.notify_source_status(options.source_name, options.source_status)
|
||||||
|
elif options.webstream:
|
||||||
|
self.notify_webstream_data(options.webstream, options.media_id)
|
||||||
|
elif options.media_id:
|
||||||
|
self.notify_media_start_playing(options.media_id)
|
||||||
|
elif options.liquidsoap_started:
|
||||||
|
self.notify_liquidsoap_started()
|
||||||
|
else:
|
||||||
|
logger.debug("Unrecognized option in options(%s). Doing nothing" \
|
||||||
|
% str(options))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -112,41 +131,9 @@ if __name__ == '__main__':
|
||||||
print '#########################################'
|
print '#########################################'
|
||||||
|
|
||||||
# initialize
|
# initialize
|
||||||
if options.error and options.stream_id:
|
|
||||||
try:
|
try:
|
||||||
n = Notify()
|
n = Notify()
|
||||||
n.notify_liquidsoap_status(options.error, options.stream_id, options.time)
|
n.run_with_options(options)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print e
|
print( traceback.format_exc() )
|
||||||
elif options.connect and options.stream_id:
|
|
||||||
try:
|
|
||||||
n = Notify()
|
|
||||||
n.notify_liquidsoap_status("OK", options.stream_id, options.time)
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
elif options.source_name and options.source_status:
|
|
||||||
try:
|
|
||||||
n = Notify()
|
|
||||||
n.notify_source_status(options.source_name, options.source_status)
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
elif options.webstream:
|
|
||||||
try:
|
|
||||||
n = Notify()
|
|
||||||
n.notify_webstream_data(options.webstream, options.media_id)
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
elif options.media_id:
|
|
||||||
|
|
||||||
try:
|
|
||||||
n = Notify()
|
|
||||||
n.notify_media_start_playing(options.media_id)
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
elif options.liquidsoap_started:
|
|
||||||
try:
|
|
||||||
n = Notify()
|
|
||||||
n.notify_liquidsoap_started()
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue