Ensure only telnetliquidsoap has telnet responsibilities

-also added module docstrings
This commit is contained in:
Martin Konecny 2013-05-16 16:19:00 -04:00
parent 888e6db812
commit 060980d8c6
13 changed files with 303 additions and 389 deletions

View file

@ -1,7 +1,20 @@
"""
schedule.pypoliqqueue
~~~~~~~~~
This module takes a collection of media_items scheduled in the near future
and fires off a start event when the item's start time begins.
:author: (c) 2012 by Martin Konecny.
:license: GPLv3, see LICENSE for more details.
"""
from threading import Thread
from collections import deque
from datetime import datetime
from schedule import pure
import traceback
import sys
import time
@ -44,7 +57,7 @@ class PypoLiqQueue(Thread):
self.pypo_liquidsoap.play(media_item)
if len(schedule_deque):
time_until_next_play = \
self.date_interval_to_seconds(
pure.date_interval_to_seconds(
schedule_deque[0]['start'] - datetime.utcnow())
if time_until_next_play < 0:
time_until_next_play = 0
@ -61,23 +74,11 @@ class PypoLiqQueue(Thread):
schedule_deque.append(media_schedule[i])
if len(keys):
time_until_next_play = self.date_interval_to_seconds(\
time_until_next_play = pure.date_interval_to_seconds(\
keys[0] - datetime.utcnow())
else:
time_until_next_play = None
def date_interval_to_seconds(self, interval):
"""
Convert timedelta object into int representing the number of seconds. If
number of seconds is less than 0, then return 0.
"""
seconds = (interval.microseconds + \
(interval.seconds + interval.days * 24 * 3600) * 10 ** 6) / float(10 ** 6)
if seconds < 0: seconds = 0
return seconds
def run(self):
try: self.main()
except Exception, e: