From 65c86a087cc048855ccc59ce005ccf6143620fec Mon Sep 17 00:00:00 2001 From: gn64_jp Date: Wed, 9 Dec 2009 00:39:22 +0000 Subject: [PATCH] fix to read xml using dom. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@306 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/classify.py | 2 -- rec10/trunk/src/epgdb.py | 10 +++--- rec10/trunk/src/missed.py | 51 ----------------------------- rec10/trunk/src/tester.py | 23 ++++++++------ rec10/trunk/src/xml2db_dom.py | 74 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 68 deletions(-) delete mode 100755 rec10/trunk/src/missed.py create mode 100644 rec10/trunk/src/xml2db_dom.py diff --git a/rec10/trunk/src/classify.py b/rec10/trunk/src/classify.py index a63368b..2a0f6ff 100644 --- a/rec10/trunk/src/classify.py +++ b/rec10/trunk/src/classify.py @@ -3,8 +3,6 @@ # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze -__author__="yukikaze" -__date__ ="$2009/09/14 17:38:25$" import glob import n_gram import os diff --git a/rec10/trunk/src/epgdb.py b/rec10/trunk/src/epgdb.py index 224d232..a8f5357 100644 --- a/rec10/trunk/src/epgdb.py +++ b/rec10/trunk/src/epgdb.py @@ -10,7 +10,7 @@ import chdb import n_gram import rec10d import ts2epg -import xml2db +import xml2db_dom import configreader import recdblist path = str(os.path.dirname(os.path.abspath(__file__))) + "/" @@ -28,26 +28,26 @@ def update(chtxt): dt = dt.days * 24 * 60 + dt.seconds if dt > 2 * 60 * 60: ts2epg.write(tmppath + chtxt + "epgdata.xml", chdb.chtxtsearch(chtxt)['ch']) - xml2db.xml2db(tmppath + chtxt + "epgdata.xml", chdb.chtxtsearch(chtxt)['bctype']) + xml2db_dom.xml2db_dom(tmppath + chtxt + "epgdata.xml", chdb.chtxtsearch(chtxt)['bctype']) def updatebc(bctype): bctypel = chdb.bctypesearch(bctype) print bctype try: ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.bctypesearch(bctype)['ch']) - xml2db.xml2db(tmppath + bctype + "epgdata.xml", bctype) + xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype) shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml") rec10d.rec10db.update_by_bctype_epg_ch(bctype) except Exception, inst: print "error occurs in updatebc(epgdb)" print type(inst) print inst - xml2db.xml2db(tmppath + bctype + "epgdata.bak.xml", bctype) + xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype) rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2") def updatebc_bak(bctype): """ update epg data by .bak file """ - xml2db.xml2db(tmppath + bctype + "epgdata.bak.xml", bctype) + xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype) def searchtime2(titletxt, timet, deltatime, chtxt): time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") ret = [] diff --git a/rec10/trunk/src/missed.py b/rec10/trunk/src/missed.py deleted file mode 100755 index ac61809..0000000 --- a/rec10/trunk/src/missed.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009 Yukikaze -import glob -import os -import time - -import configreader -import recdblist -dbpath = str(os.path.dirname(os.path.abspath(__file__))) + "/" + "ch.db" -if __name__ == "__main__": - recdblist.printutf8("Hello Rec10 Recording Que Search.") -def search_b25(path): - """ - 録画フォルダを検索し、各QUEの実行状況を表示する - """ - b25list = glob.glob(path + "/*.b25") - for b25f in b25list: - ##b25f is title.ts.b25 avi is title.avi - dir = os.path.split(b25f)[0] - title = os.path.split(b25f)[1] - title = title.replace(".ts.b25", "") - avipath = os.path.join(dir, title + ".avi") - tspath = os.path.join(dir, title + ".ts") - b25f = b25f.replace(".ts.b25", ".avi") - mode = "ts" - if os.path.isfile(tspath):##tsファイルが存在している - dtime = time.time()-os.path.getmtime(tspath) - dtime = int(dtime) - if dtime > 120: - if os.path.getsize(tspath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上 - mode = "avi" - else: - mode = "tsmiss" - else: - mode = "ts" - if os.path.isfile(avipath):##tsファイルが存在している - dtime = time.time()-os.path.getmtime(avipath) - dtime = int(dtime) - if dtime > 120: - if os.path.getsize(avipath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上 - mode = "fin" - else: - mode = "avimiss" - else: - mode = "avi" - recdblist.printutf8(title + ":" + mode) - -path = configreader.getpath("recpath") -search_b25(path) diff --git a/rec10/trunk/src/tester.py b/rec10/trunk/src/tester.py index d0b105d..6c94f74 100644 --- a/rec10/trunk/src/tester.py +++ b/rec10/trunk/src/tester.py @@ -3,15 +3,15 @@ # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze #import sys -#import os -#import datetime -import rec10d import os +#import datetime +#import rec10d +#import os #import time -import n_gram -import profile -import epgdb -import recdblist +#import n_gram +#import profile +#import epgdb +#import recdblist #import status #import chdb #import checker @@ -24,8 +24,9 @@ import recdblist #import tv2avi #import xml2db #import guess -import zenhan -import auto_process +#import zenhan +#import auto_process +import xml2db_dom __author__ = "yukikaze" __date__ = "$2009/08/01 22:25:13$" path = str(os.path.dirname(os.path.abspath(__file__))) + "/" @@ -68,4 +69,6 @@ if __name__ == "__main__": #recdblist.printutf8(zenhan.check_Character_Type()) #auto_process.Update_to_MP4("") #rec10d.rec10db.add_recjbk("畑健二郎") - "" \ No newline at end of file + xml2db_dom.xml2db_dom("C:\\Users\\yukikaze\\Desktop\\bsepgdata.xml","") + "" + \ No newline at end of file diff --git a/rec10/trunk/src/xml2db_dom.py b/rec10/trunk/src/xml2db_dom.py new file mode 100644 index 0000000..92d35ca --- /dev/null +++ b/rec10/trunk/src/xml2db_dom.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009 Yukikaze + +import xml.dom.minidom +import zenhan +import chdb +import auto_rec +import recdb + +def getText(elm): + nodelist = elm.childNodes + rc = "" + # 全てのノードに対して + for node in nodelist: + # テキストノードなら値を取得 + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + return rc +def getText_item(obj): + rc="" + for o in obj: + rc=rc+getText(o) + return rc +def writemultitvDB(bctype,tvlists): + rec10d.rec10db.new_epg_timeline(bctype) + for channel,start,stop,title,desc,longdesc,category in tvlists: + rec10d.rec10db.add_epg_timeline(bctype, channel, start, stop, title, desc, longdesc, category) +def writemultichDB(bctype,chlists): + for ontv,dn in chlists: + rec10d.rec10db.update_chname_by_ontv_epg_ch(ontv, dn) +def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る + dtb=datetime.datetime.now() + dom=xml.dom.minidom.parse(file(xmlpath)) + chlist=[] + tvlist=[] + bayes={} + for ch in dom.getElementsByTagName('channel'): + ontv=ch.getAttribute("id") + chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data + chlist.append([ontv,chname]) + for tv in dom.getElementsByTagName('programme'): + channel=zenhan.toHankaku_ABC123(tv.getAttribute("channel")) + start=tv.getAttribute("start").replace(" +0900", "") + stop=tv.getAttribute("stop").replace(" +0900", "") + title=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("title"))).replace(",", "_") + desc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("desc"))) + longdesc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("longdesc"))) + category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category"))) + tch=chdb.ontvsearch(channel) + if tch!=None: + if tch.get('bctype',"")==ubctype: + bt=bayes.get(tch['chtxt'],["","",0]) + bt2=[bt[0]+title+" ",bt[1]+desc+" "+longdesc+" ",bt[2]+1] + bayes[tch['chtxt']]=bt2 + tvlist.append([channel,start,stop,title,desc,longdesc,category]) + p=auto_rec.calc_key(tch['chtxt'], title,desc+" "+longdesc) + if p>2000: + recdb.add_auto_bayes(tch['chtxt'],title,start,stop,p) + dom.unlink() + if len(chlist) > 0: + writemultichDB(chlist) + chlist = [] + if len(tvlist) > 0: + writemultitvDB(tvlist) + tvlist = [] + for ct,list in bayes.items(): + auto_rec.update_recall(ct,list[0],list[1],list[2]) + auto_rec.update_recall("ALL",list[0],list[1],list[2]) + dtb=datetime.datetime.now()-dtb + recdblist.printutf8(bctype + u" epg取り出し終了") + recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .") + -- 2.11.0