def xmltv_creator(self): if xbmc.abortRequested == True: sys.exit() w = XMLWriter.XMLWriter(self.tmpFile, encoding='utf-8') w.start("tv") for channel in self.dummyData: try: channel = channel["channel"] programme = "%s/%s.xml" % (self.tmpFolder, channel) if os.path.isfile(programme): w.start("channel", id=channel) w.element("display-name", channel) w.element("icon", src="%s/%s.png" % (self.logoFolder, channel)) w.element( "stream", "plugin://plugin.video.hellenic.tv/?action=play_video&channel=%s" % channel.replace(' ', '_')) w.end() except: pass for channel in self.dummyData: try: channel = channel["channel"] programme = "%s/%s.xml" % (self.tmpFolder, channel) r = open(programme, "r") w = open(self.tmpFile, 'a') [w.write(line) for line in r] r.close() w.close() except: pass w = open(self.tmpFile, 'a') w.write("</tv>") w.close()
def diff(source1, source2, dest, config): IDS = config["IDS"] REQUIRED_ATTRS = config["REQUIRED_ATTRS"] (fname1, need_cleanup1) = process_source(source1) (fname2, need_cleanup2) = process_source(source2) try: p = parser.Parser() parsed1 = p.parse_file(open(fname1)) p = parser.Parser() parsed2 = p.parse_file(open(fname2)) dest = open(dest, "w") diffed = parsed1.diff(parsed2, path="", ids=IDS, required=REQUIRED_ATTRS) del parsed1, parsed2 writer = xmlwriter.XMLWriter(dest, encoding="utf-8") writer.start_document() saxxml.diff_tree2xml(writer, diffed, required_attrs=REQUIRED_ATTRS) writer.end_document() except Exception: raise finally: if need_cleanup1: os.remove(fname1) if need_cleanup2: os.remove(fname2)
def programme_creator(self, channel, programmeList): if xbmc.abortRequested == True: sys.exit() w = XMLWriter.XMLWriter("%s/%s.xml" % (self.tmpFolder, channel), encoding='utf-8') for i in range(0, len(programmeList)): start = programmeList[i]['start'] try: stop = programmeList[i + 1]['start'] except: stop = programmeList[i]['start'] title = programmeList[i]['title'] desc = programmeList[i]['desc'] w.start("programme", channel=channel, start=start, stop=stop) w.element("title", title, lang="el") w.element("desc", desc) w.end()
# only elements and attributes which are different. But of course you want # to know at least id of group that contains different sub-elements. # REQUIRED_ATTRS ensure you, that if specified objects are different at least # at one pair attributes, output will contain also elements or attributes # from first source which are specified in REQUIRED_ATTRS. REQUIRED_ATTRS = {"group": ["id"], "category": ["id"], "environment": ["id"]} # Now do a diff thing. Path parameter is needed because diff method is called # recursively. So we start with empty path diffed = parsed1.diff(parsed2, path="", ids=IDS, required=REQUIRED_ATTRS) # Remove original structures, because they are changed and useless now. # And also because this example and whole tool is memory green. del parsed1, parsed2 writer = xmlwriter.XMLWriter(sys.stdout, encoding="utf-8") writer.start_document() # write output to stdout. In saxxml module is also method tree2xml # rendering ordinary xml. # So you can call - but not at this point becaused parsed1 is already deleted # saxxml.tree2xml(writer, parsed1) # to render xml from parsed structure saxxml.diff_tree2xml(writer, diffed, required_attrs=REQUIRED_ATTRS) writer.end_document()