def fromJSON(cls, prog, db=None): dat = {} CopyData(prog, dat, ('Title', 'SubTitle', 'SeriesId', 'ProgramId', 'Airdate', 'Category', 'Hostname', 'ProgramFlags', 'Stars', 'FileSize', 'Description'), True) CopyData(prog['Channel'], dat, ('ChanId', 'CallSign', 'ChanNum', 'InputId', 'SourceId'), True) CopyData2(prog['Channel'], dat, (('ChannelName', 'channame'),)) CopyData(prog['Recording'], dat, ('DupMethod', 'PlayGroup', 'RecType', 'RecordId'), True) CopyData2(prog['Recording'], dat, (('DupInType', 'dupin'), ('Status', 'recstatus'))) for k,v in (('starttime', prog['StartTime']), ('endtime', prog['EndTime']), ('recstartts', prog['Recording']['StartTs']), ('recendts', prog['Recording']['EndTs']), ('lastmodified', prog['LastModified'])): if v: dat[k] = str(datetime.fromIso(v).timestamp()) raw = [] defs = (0,0,0,'',0,'') for i,v in enumerate(cls._field_order): if v in dat: raw.append(dat[v]) else: raw.append(defs[cls._field_type[i]]) return cls(raw, db)
def fromEtree(cls, etree, db=None): xmldat = dict(etree.attrib) xmldat.update(etree.find('Channel').attrib) if etree.find('Recording') is not None: xmldat.update(etree.find('Recording').attrib) dat = {} if etree.text: dat['description'] = etree.text.strip() for key in ('title','subTitle','seriesId','programId','airdate', 'category','hostname','chanNum','callSign','playGroup', 'recGroup','rectype','programFlags','chanId','recStatus', 'commFree','stars','filesize'): if key in xmldat: dat[key.lower()] = xmldat[key] for key in ('startTime','endTime','lastModified', 'recStartTs','recEndTs'): if key in xmldat: dat[key.lower()] = str(datetime.fromIso(xmldat[key])\ .timestamp()) raw = [] defs = (0,0,0,'',0,'') for i,v in enumerate(cls._field_order): if v in dat: raw.append(dat[v]) else: raw.append(defs[cls._field_type[i]]) return cls(raw, db)
def fromJSON(cls, prog, db=None): dat = {} for key in ('ChanId','Title','SubTitle','Category'): dat[key.lower()] = prog[key] for key,key2 in (('CatType', 'category_type'),): dat[key2] = prog[key] for key in ('StartTime', 'EndTime'): dat[key.lower()] = datetime.fromIso(prog[key]) dat['airdate'] = dat['starttime'].year raw = [] for key in db.tablefields[cls._table]: if key in dat: raw.append(dat[key]) else: raw.append(None) return cls.fromRaw(raw, db)
def fromEtree(cls, etree, db=None): dat = {'chanid':etree[0]} attrib = etree[1].attrib for key in ('title','subTitle','category','seriesId', 'hostname','programId','airdate'): if key in attrib: dat[key.lower()] = attrib[key] if 'stars' in attrib: dat['stars'] = locale.atof(attrib['stars']) if etree[1].text: dat['description'] = etree[1].text.strip() for key in ('startTime','endTime','lastModified'): if key in attrib: dat[key.lower()] = datetime.fromIso(attrib[key]) raw = [] for key in db.tablefields[cls._table]: if key in dat: raw.append(dat[key]) else: raw.append(None) return cls.fromRaw(raw, db)
def getTime(self): """Returns current time on frontend.""" return datetime.fromIso(self.sendQuery('time'))