From b044e0f011b97910cc9d8671a6ae499215454249 Mon Sep 17 00:00:00 2001 From: echarlie Date: Tue, 7 Jun 2022 21:07:34 -0400 Subject: [PATCH 1/3] implement basic underwriting queue support and queue underwriting script, since the api never materialised --- radio.liq | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/radio.liq b/radio.liq index d9769c4..427de4b 100644 --- a/radio.liq +++ b/radio.liq @@ -2,15 +2,16 @@ %include "config.liq" -def underwriting_request() = - result = list.hd(default="", get_process_lines( - "curl -fsL #{playlist_api_url}/underwriting")) - if result == "" then - [] - else - [request.create(result)] - end -end +# UNDERWRITING API not implemented +#def underwriting_request() = +# result = list.hd(default="", get_process_lines( +# "curl -fsL #{playlist_api_url}/underwriting")) +# if result == "" then +# [] +# else +# [request.create(result)] +# end +#end def next_track_request() = result = list.hd(default="", get_process_lines( @@ -114,11 +115,13 @@ def log_metadata_async(m) = end # create underwriting queue - if API is disabled, just leave it empty -underwriting = if playlist_api_url != "" then - eat_blank(audio_to_stereo(request.dynamic.list(id="underwriting", retry_delay=900., underwriting_request))) -else - empty(id="underwriting") -end +#underwriting = if playlist_api_url != "" then +# eat_blank(audio_to_stereo(request.dynamic.list(id="underwriting", retry_delay=900., underwriting_request))) +#else +# empty(id="underwriting") +#end + +underwriting = empty(id="underwriting") # build up the track queues; provide a local one and one that uses the API tracks_local = request.dynamic.list(id="tracks_local", next_track_local_request) From d270e9713c11bf41d60a334baef7734883ff0521 Mon Sep 17 00:00:00 2001 From: echarlie Date: Tue, 7 Jun 2022 21:08:25 -0400 Subject: [PATCH 2/3] restore queue underwriting file --- queue_underwriting.py | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 queue_underwriting.py diff --git a/queue_underwriting.py b/queue_underwriting.py new file mode 100644 index 0000000..2ad291a --- /dev/null +++ b/queue_underwriting.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 + +import yaml +import datetime +import calendar +import socket +import random +import sys + +underwritingSchedule = '/tmp/sample.yml' +telnetHost = '172.17.0.2' +telnetPort = 1234 + +underwriters = yaml.safe_load(open(underwritingSchedule)) +thisHour = [] + + +def push_command(url): + cmd = "underwriting.push {}\n".format(url).encode('utf-8') + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + sock.connect((telnetHost, telnetPort)) + except OSError as e: + print("Cannot push to socket: {0}".format(e)) + return False + # queue the first one immediately + sock.send(cmd) + if datetime.datetime.now().minute > 30: + # we must be queuing for the next hour, so add the second + sock.send(cmd) + sock.send(b'exit\n') + return True + + +# check which hour we're queuing for and return datetime object +def what_hour(): + queue_hour = datetime.datetime.now() + if queue_hour.minute > 30: + # queuing for next hour + queue_hour = queue_hour + datetime.timedelta(hours=1) + return queue_hour + + +queue_hour = what_hour() + +for underwriting in underwriters: + today = queue_hour.date() + weekday = calendar.day_name[queue_hour.weekday()].lower() + # we want to sanely handle do-not-kill situations + if ((not underwriting['startdate'] or + underwriting['startdate'] <= today) and + (not underwriting['enddate'] or + underwriting['enddate'] >= today))and\ + weekday in underwriting['schedule'] and\ + queue_hour.hour in underwriting['schedule'][weekday]: + if len(underwriting['url']) > 1: + # Then we probably have multiple recordings of the grant statement + playFile = random.choice(underwriting['url']) + else: + # we probably don't need this, since a random int between 0 and 0 + # is 0 + playFile = underwriting['url'][0] + # probably the safer way to handle things in the future, but would + # require more parsing + # thisHour[underwriting['name']] = playFile + thisHour.append(playFile) + +# because automation currently only plays one piece of underwriting at a time, +# we need arbitrate which piece we push. We'll pick a random one! +if len(thisHour) is not 0: + if push_command(random.choice(thisHour)): + # ideally, we would list what underwriting was queued, but we're being + # kind of sloppy with cases of overlapping underwriting + if len(thisHour) > 1: + print("There are {} underwriters this hour!".format(len(thisHour))) + print("Underwriting queued for {}".format(queue_hour)) + else: + print("Failed to queue underwriting for {}".format(queue_hour)) + sys.exit(1) +else: + print("No underwriting to queue for {}".format(queue_hour)) From b81d5b9901f990cdfc6e7b797b8c41484df8e2fc Mon Sep 17 00:00:00 2001 From: echarlie Date: Mon, 13 Jun 2022 20:39:31 -0400 Subject: [PATCH 3/3] request.queue --- radio.liq | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio.liq b/radio.liq index 427de4b..233ae51 100644 --- a/radio.liq +++ b/radio.liq @@ -121,7 +121,7 @@ end # empty(id="underwriting") #end -underwriting = empty(id="underwriting") +underwriting = request.queue(id="underwriting") # build up the track queues; provide a local one and one that uses the API tracks_local = request.dynamic.list(id="tracks_local", next_track_local_request)