def theLoop(adapters,log): log.debug("starting scheduler class") sch=Schedule(log) while 1: log.debug("starting loop") log.debug("updating schedule") sch.makeschedule() row=sch.getnextschedule() now=int(time.time()) left=3600 togo=3600 if len(row): togo=row["start"] - now log.debug("next recording: %s in %s" % (row["title"],timeformat(togo))) else: log.debug("no recordings scheduled") rrows=sch.getcurrentrecordings() cn=len(rrows) if cn: log.debug("%d programmes currently being recorded" % cn) nextend=rrows[0]["end"] left=nextend - now log.debug("%s finishes in %s" % (rrows[0]["title"],timeformat(left))) else: log.debug("nothing currently recording") if togo<left: timeleft=togo else: timeleft=left log.debug("sleeping for %s" % timeformat(timeleft)) signal.alarm(left) signal.pause() log.debug("ending loop")
from schedule import Schedule log=logging.getLogger("cristel") if __name__ == '__main__': left=3600 togo=3600 log.setLevel(logging.DEBUG) handler=logging.handlers.SysLogHandler(address = '/dev/log', facility=logging.handlers.SysLogHandler.LOG_DAEMON) log.addHandler(handler) prog=os.path.basename(__file__) log.debug("starting scheduler class") sch=Schedule(log) log.debug("updating schedule") sch.makeschedule() row=sch.getnextschedule() if row != None: now=int(time.time()) togo=row["start"] - now log.info("next recording: %s in %d seconds" % (row["title"],togo)) else: log.info("no recordings scheduled") rrows=sch.getcurrentrecordings() cn=len(rrows) if cn: log.debug("%d programmes currently being recorded" % cn) nextend=rrows[0]["end"] left=nextend - now log.debug("%s finishes in %d seconds" % (rrows[0]["title"],left))