OSDN Git Service

change many function.
[rec10/rec10-git.git] / rec10 / trunk / src / chdb.py
index bdbcaef..0a55525 100644 (file)
 # coding: UTF-8
 # Rec10 TS Recording Tools
 # Copyright (C) 2009 Yukikaze
- # モジュール属性 argv を取得するため
-import os
-import sqlite3
-
-dbpath=str(os.path.dirname(os.path.abspath(__file__)))+"/"+"ch.db"
-#db=sqlite3.connect(dbpath)
+    # モジュール属性 argv を取得するため
+import rec10d
 
 def ontvsearch(ontvin):
-    db=sqlite3.connect(dbpath)
-    ret=[]
-    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ontv = \""+ontvin+"\""):
-        rett={'bctype':bctype,'ontv':ontv,'chtxt':chtxt,'ch':ch,'csch':csch,'update':updatetime}
+    ret = []
+    for datum in rec10d.rec10db.select_by_ontv_epg_ch(ontvin):
+        rett = {'bctype':datum[0], 'ontv':datum[1], 'chtxt':datum[2], 'ch':datum[3], 'csch':datum[4], 'update':datum[5]}
         ret.append(rett)
-    db.close()
+    if len(ret) == 0:
+        ret.append(None)
     return ret[0]
 def chtxtsearch(chtxtin):
-    db=sqlite3.connect(dbpath)
-    ret=[]
-    print chtxtin
-    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE chtxt = \""+chtxtin+"\""):
-        rett={'bctype':bctype,'ontv':ontv,'chtxt':chtxt,'ch':ch,'csch':csch,'update':updatetime}
-        #print rett
+    ret = []
+    for datum in rec10d.rec10db.select_by_chtxt_epg_ch(chtxtin):
+        rett = {'bctype':datum[0], 'ontv':datum[1], 'chtxt':datum[2], 'ch':datum[3], 'csch':datum[4], 'update':datum[5]}
         ret.append(rett)
-    db.close()
+    if len(ret) == 0:
+        ret.append(None)
     return ret[0]
 def bctypesearch(bctypein):
-    db=sqlite3.connect(dbpath)
-    ret=[]
-    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE bctype = \""+bctypein+"\""):
-        rett={'bctype':bctype,'ontv':ontv,'chtxt':chtxt,'ch':ch,'csch':csch,'update':updatetime}
-        #print rett
+    ret = []
+    for datum in rec10d.rec10db.select_by_bctype_epg_ch(bctypein):
+        rett = {'bctype':datum[0], 'ontv':datum[1], 'chtxt':datum[2], 'ch':datum[3], 'csch':datum[4], 'update':datum[5]}
         ret.append(rett)
-    db.close()
+    if len(ret) == 0:
+        ret.append(None)
     return ret[0]
 def chsearch(chin):
-    db=sqlite3.connect(dbpath)
-    ret=[]
-    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ch = \""+chin+"\""):
-        rett={'bctype':bctype,'ontv':ontv,'chtxt':chtxt,'ch':ch,'csch':csch,'update':updatetime}
-        #print rett
+    ret = []
+    for datum in rec10d.rec10db.select_by_ch_epg_ch(chin):
+        rett = {'bctype':datum[0], 'ontv':datum[1], 'chtxt':datum[2], 'ch':datum[3], 'csch':datum[4], 'update':datum[5]}
         ret.append(rett)
-    db.close()
+    if len(ret) == 0:
+        ret.append(None)
     return ret[0]
 def getall():
-    db=sqlite3.connect(dbpath)
-    ret=[]
-    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata"):
-        rett={'bctype':bctype,'ontv':ontv,'chtxt':chtxt,'ch':ch,'csch':csch,'update':updatetime}
-        #print rett
+    ret = []
+    for datum in rec10d.rec10db.select_all_epg_ch():
+        rett = {'bctype':datum[0], 'ontv':datum[1], 'chtxt':datum[2], 'ch':datum[3], 'csch':datum[4], 'update':datum[5]}
         ret.append(rett)
-    db.close()
-    print ret
+    if len(ret) == 0:
+        ret.append(None)
     return ret[0]
-
 def update():
-    db=sqlite3.connect(dbpath)
-    ret=[]
-    CSupdate=0
-    CS2update=0
-    BSupdate=0
-    for bctype , chtxt in db.execute("SELECT bctype,chtxt FROM chdata WHERE updatetime < datetime(\'now\',\'localtime\',\'-6 hours\')"):
-        print bctype
-        if bctype=="cs" or bctype==u"cs":
-            if CSupdate==0:
-                ret.append(u"cs")
-                CSupdate=1
-                print "csの番組表取得開始"
-                db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE bctype = \""+bctype+"\"")
-        elif bctype=="cs2" or bctype==u"cs2":
-            if CS2update==0:
+    ret = []
+    CSupdate = 0
+    CS2update = 0
+    BSupdate = 0
+    for datum in rec10d.rec10db.select_get_update_epg_ch("6"):
+        bctype = datum[0]
+        if bctype == "cs1" or bctype == u"cs1":
+            if CSupdate == 0:
+                ret.append(u"cs1")
+                CSupdate = 1
+        elif bctype == "cs2" or bctype == u"cs2":
+            if CS2update == 0:
                 ret.append(u"cs2")
-                CS2update=1
-                print "cs2の番組表取得開始"
-                db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE bctype = \""+bctype+"\"")
-        elif bctype=="bs" or bctype==u"bs":
-            if BSupdate==0:
+                CS2update = 1
+        elif bctype == "bs" or bctype == u"bs":
+            if BSupdate == 0:
                 ret.append(u"bs")
-                BSupdate=1
-                print "bsの番組表取得開始"
-                db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE bctype = \""+bctype+"\"")
+                BSupdate = 1
         else:
             ret.append(bctype)
-            print bctype
-            print "取得開始"
-            db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE bctype = \""+bctype+"\" AND chtxt = \""+chtxt+"\"")
-    #db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE updatetime < datetime(\'now\',\'localtime\',\'-2 hours\')")
-    db.commit()
-    db.close()
-    print ret
-    return ret
-def viewall():
-    db=sqlite3.connect(dbpath)
-    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata"):
-        print (bctype+","+ontv+","+chtxt+","+ch+","+csch+","+updatetime)
-    db.close()
-#def updateall():
-
-       
+    return ret
\ No newline at end of file