OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / trunk / src / epgdb.py
index 2b9993f..727209d 100644 (file)
@@ -1,12 +1,13 @@
 #!/usr/bin/python
 # coding: UTF-8
 # Rec10 TS Recording Tools
-# Copyright (C) 2009-2010 Yukikaze
+# Copyright (C) 2009-2011 Yukikaze
 import datetime
 import os
 import shutil
 import time
 import os.path
+import traceback
 
 import chdb
 import n_gram
@@ -16,42 +17,50 @@ import xml2db_dom
 import configreader
 import recdblist
 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
-tmppath = configreader.getpath("tmp")+"/"
+tmppath = configreader.getConfPath("tmp")+"/"
 if tmppath=="/":
     tmppath=path
+if not os.path.exists(tmppath):
+    os.mkdir(tmppath)
 def update(chtxt):
     recdblist.printutf8(chtxt)
     tnow = datetime.datetime.now()
     try:
-        lastup = datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
+        lastup = datetime.datetime.strptime(chdb.searchCHFromChtxt(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
     except:
         lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")
     dt = tnow-lastup
     dt = dt.days * 24 * 60 + dt.seconds
     if dt > 2 * 60 * 60:
-        ts2epg.write(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.chtxtsearch(chtxt)['ch'])
-        xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.chtxtsearch(chtxt)['bctype'])
+        ts2epg.writeEpgXML(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['ch'])
+        xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['bctype'])
 def updatebc(bctype):
-    bctypel = chdb.bctypesearch(bctype)
+    bctypel = chdb.searchCHFromBctype(bctype)
     #print bctype
     try:
-        ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.bctypesearch(bctype)['ch'])
+        ts2epg.writeEpgXML(tmppath + bctype + "epgdata.xml", chdb.searchCHFromBctype(bctype)['ch'])
         xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype)
         shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")
         time.sleep(5)
         rec10d.rec10db.update_by_bctype_epg_ch(bctype)
     except Exception, inst:
-        recdblist.printutf8("error occurs in updatebc(epgdb)")
-        recdblist.printutf8(str(type(inst)))
-        recdblist.printutf8(str(inst))
+        recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)
         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_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)
-def searchtime2(titletxt, timet, deltatime, chtxt):
+def updateLogo_bc(bctype):
+    bctypel = chdb.searchCHFromBctype(bctype)
+    #print bctype
+    try:
+        ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch'])
+        xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype)
+        shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml")
+        time.sleep(5)
+        rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1")
+    except Exception, inst:
+        recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)
+        xml2db_dom.xml2db_dom(tmppath + bctype + "logo.bak.xml", bctype)
+        rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"2")
+def searchTime(titletxt, timet, deltatime, chtxt):
     time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
     ret = []
     deltatime = int(deltatime)
@@ -62,7 +71,8 @@ def searchtime2(titletxt, timet, deltatime, chtxt):
     aftertime = aftertime.strftime("%Y%m%d%H%M%S")
     one = ["", "", "", "","","",""]
     tempt = 0
-    d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxt)
+    chtxtt=chtxt.replace("_0","_%")
+    d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt)
     for chtxtt, title, start, stop ,exp,longexp,category in d:
         #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop)
         p = n_gram.bigram(titletxt, title)
@@ -87,7 +97,7 @@ def searchtime2(titletxt, timet, deltatime, chtxt):
     ret = one
     #print ret
     return ret
-def searchtime_auto(keytxt, timet, deltatime):
+def searchTimeAuto(keytxt, timet, deltatime):
     time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
     ret = []
     deltatime = int(deltatime)
@@ -102,7 +112,7 @@ def searchtime_auto(keytxt, timet, deltatime):
         etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
         ret.append([chtxtt, title, btime, etime,exp,longexp,category])
     return ret
-def count_schedule(btime,etime):
+def countSchedule(btime,etime):
     """
     return rec num (int return[0]:TE /int return[1]:BS/CS)
     """
@@ -144,7 +154,7 @@ def count_schedule(btime,etime):
             retcount[1] = ret1[1]
     return retcount
 
-def search_schedule(btime,etime):
+def searchSchedule(btime,etime):
     """
     return rec num (int return[0]:TE /int return[1]:BS/CS)
     """
@@ -184,7 +194,7 @@ def search_schedule(btime,etime):
     ret = list(set(ret))
     return ret
 
-def count_epgschedule(epgbtime,epgetime):
+def countEpgSchedule(epgbtime,epgetime):
     """
     return rec num (int return[0]:TE /int return[1]:BS/CS)
     """
@@ -226,7 +236,7 @@ def count_epgschedule(epgbtime,epgetime):
         if retcount[1] < ret1[1]:
             retcount[1] = ret1[1]
     return retcount
-def search_epgschedule(epgbtime,epgetime):
+def searchEpgSchedule(epgbtime,epgetime):
     """
     return rec num (int return[0]:TE /int return[1]:BS/CS)
     """
@@ -264,4 +274,4 @@ def search_epgschedule(epgbtime,epgetime):
         ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1)
         ret.append(ret1)
     ret = list(set(ret))
-    return ret
\ No newline at end of file
+    return ret