#!/usr/bin/python # -*- coding: UTF-8 -*- ''' TVguide (c) 2014-2015 Jan ONDREJ (SAL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ''' from __future__ import absolute_import from __future__ import print_function import time, socket from media import urlopen, URLError from datetime import datetime from xml.dom.minidom import parseString from xml.parsers.expat import ExpatError from lxml import etree class prog(): def __init__(self, **kw): self.id = kw['id'] self.name = kw.get('title') if 'sub-title' in kw: self.name += ": " + kw.get('sub-title') self.description = kw.get('desc') self.tv = kw['id'] self.category = kw.get('category') self.time = kw.get("start") self.start = time.mktime(time.strptime( kw.get("start").split(" ")[0], "%Y%m%d%H%M%S" )) self.stop = time.mktime(time.strptime( kw.get("stop").split(" ")[0], "%Y%m%d%H%M%S" )) self.seconds = self.stop - self.start self.img = kw.get('img') def __repr__(self): return '' \ % (self.time, self.seconds, repr(self.name)) def gettime(self): #return time.mktime(time.gmtime()) return time.time() def is_current(self): #print self.gettime()-self.start, self.stop-self.gettime(), self.time, self.seconds return self.start<=self.gettime()int_stop: continue data = {} for subentry in nodes: data[subentry.tag] = subentry.text if channel not in guide: guide[channel] = {} guide[channel][start] = prog( id=channel, start=start, stop=stop, **data ) return guide def current(self, channel, try_reload=True): if self.guide is None: self.reload_current() if channel in self.guide: for value in self.guide[channel].values(): if value.is_current(): return value if try_reload: self.reload_current() return self.current(channel, False) return None def current_name(self, channel): current = self.current(channel) if current is None: return "" return current.name tv_program = tvguide_class() if __name__ == "__main__": import sys print(tv_program.current(sys.argv[1])) print("%5.2f %%" % (tv_program.current(sys.argv[1]).progress()*100.0))