From 6d09e063ab56cc40e3432a66a8d8b64ffa987f7d Mon Sep 17 00:00:00 2001 From: gn64_jp Date: Sun, 2 Aug 2009 02:27:33 +0000 Subject: [PATCH] put DB accessing functions together(dbSQLite.py). git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@87 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/chdata.py | 42 ++--- rec10/trunk/src/chdb.py | 71 +++------ rec10/trunk/src/dbSQLite.py | 372 ++++++++++++++++++++++++++++---------------- rec10/trunk/src/epgdb.py | 62 ++------ rec10/trunk/src/install.py | 4 +- rec10/trunk/src/missed.py | 49 ------ rec10/trunk/src/rec10d.py | 5 +- rec10/trunk/src/status | 1 + rec10/trunk/src/tester.py | 16 ++ rec10/trunk/src/xml2db.py | 2 +- 10 files changed, 301 insertions(+), 323 deletions(-) create mode 100644 rec10/trunk/src/tester.py diff --git a/rec10/trunk/src/chdata.py b/rec10/trunk/src/chdata.py index 5f044bc..334c495 100644 --- a/rec10/trunk/src/chdata.py +++ b/rec10/trunk/src/chdata.py @@ -2,33 +2,11 @@ # coding: UTF-8 # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze -import sqlite3 - -import os +import rec10d #CS放送では複数のチャンネルを指定する必要があるためチャンネル名をテキストデータで持っておき(chtxt)、必要に応じて変換する #ontvはepgデータなどで指定されている名前 #ここの設定は愛知県の設定(+CS放送スカパーe2 +BS) -dbpath = str(os.path.dirname(os.path.abspath(__file__))) + "/" + "ch.db" -#db=sqlite3.connect(dbpath) -db = sqlite3.connect(dbpath) -try: - - db.execute('drop table chdata') - db.commit() -except: - test = "" - -try: - db.execute('create table chdata (bctype TEXT,ontv TEXT,chtxt TEXT,ch TEXT,csch TEXT,station TEXT,station_name TEXT,updatetime TEXT)') -except: - "" -db.commit() - -#except: -# print "テーブル作成に失敗しました" -# db.commit() -#db.commit() -db.close() +rec10d.rec10db.new_chdata() def chadd(bctype, ontv, chtxt, ch, csch, station, station_name):#すべて文字列 """ ChannelDBに指定したデータを追加する @@ -37,13 +15,15 @@ def chadd(bctype, ontv, chtxt, ch, csch, station, station_name):#すべて文字 te(地上波)は各チャンネルごとに設定する必要があるためteに チャンネルの数字を足したものにする """ - db = sqlite3.connect(dbpath) - value = "(\'" + bctype + "\',\'" + ontv + "\',\'" + chtxt + "\',\'" + ch + "\',\'" + csch + "\',\'" + station + "\',\'" + station_name + "\',datetime(\'2009-04-01 00:00:00\'))" - print value - value = unicode(value) - db.execute('insert into chdata values ' + value) - db.commit() - db.close() + ubct=unicode(bctype) + uontv=unicode(ontv) + uchtxt=unicode(chtxt) + uch=unicode(ch) + ucsch=unicode(csch) + ustation=unicode(station) + ustaname=unicode(station_name) + rec10d.rec10db.add_chdata(ubct,uontv,uchtxt,uch,ucsch,ustation,ustaname,u"2009-04-01 00:00:00") + #db.commit #チャンネルの設定 diff --git a/rec10/trunk/src/chdb.py b/rec10/trunk/src/chdb.py index bdbcaef..fde83d6 100644 --- a/rec10/trunk/src/chdb.py +++ b/rec10/trunk/src/chdb.py @@ -3,100 +3,77 @@ # 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) +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} + for datum in rec10d.rec10db.select_by_ontv_chdata(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() 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 + for datum in rec10d.rec10db.select_by_chtxt_chdata(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() 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 + for datum in rec10d.rec10db.select_by_bctype_chdata(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() 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 + for datum in rec10d.rec10db.select_by_ch_chdata(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() 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 + for datum in rec10d.rec10db.select_all_chdata(): + 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 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\')"): + for datum in rec10d.rec10db.select_get_update_chdata("6"): + bctype=datum[0] + chtxt=datum[1] 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+"\"") + rec10d.rec10db.update_by_bctype_chdata(bctype) 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+"\"") + rec10d.rec10db.update_by_bctype_chdata(bctype) 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+"\"") + rec10d.rec10db.update_by_bctype_chdata(bctype) 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() + rec10d.rec10db.update_by_bctype_and_chtxt_chdata(bctype,chtxt) 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 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(): - +#print ontvsearch("1062.ontvjapan.com") diff --git a/rec10/trunk/src/dbSQLite.py b/rec10/trunk/src/dbSQLite.py index 66ddf1a..a0a3c88 100644 --- a/rec10/trunk/src/dbSQLite.py +++ b/rec10/trunk/src/dbSQLite.py @@ -2,150 +2,246 @@ # coding: UTF-8 # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze -#import sys -#import os + import sqlite3 import recdb +import os +import time #db.execute('create table rectime #(type TEXT,chtxt TEXT,title TEXT,btime TEXT,etime TEXT,deltatime TEXT,deltaday TEXT,opt TEXT,id INTEGER PRIMARY KEY,UNIQUE(type,chtxt,title,btime,deltaday))') -path=str(os.path.dirname(os.path.abspath(__file__)))+"/" -dbpath=path+"ch.db" -def __inif__(self,value): - dbpath=value - db=sqlite3.connect(dbpath) - try: - db.execute('create table rectime (type TEXT,chtxt TEXT,title TEXT,btime TEXT,etime TEXT,deltatime TEXT,deltaday TEXT,opt TEXT,id INTEGER PRIMARY KEY,UNIQUE(type,chtxt,title,btime,deltaday))') - except: - "" -def connect_db(tout=10): - global dbpath - """ - dbへの接続(timeoutは秒) +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +dbpath = path + "ch.db" +class DB_SQLite(): + dbpath="" + def __init__(self,dbpath): + self.dbpath = dbpath + db = self.connect_db(60) + try: + db.execute('create table rectime (type TEXT,chtxt TEXT,title TEXT,btime TEXT,etime TEXT,deltatime TEXT,deltaday TEXT,opt TEXT,id INTEGER PRIMARY KEY,UNIQUE(type,chtxt,title,btime,deltaday))') + except: + "" + db.commit + self.close_db(db) + def connect_db(self,tout=10): + global dbpath + """ + dbへの接続(timeoutは秒) + + """ + tout=tout*1000 + return sqlite3.connect(self.dbpath, timeout=tout) + def close_db(self,db): + db.close() + def new_chdata(self): + db = self.connect_db(60) + try: + db.execute('drop table chdata') + db.commit() + except: + "" + try: + db.execute('create table chdata (bctype TEXT,ontv TEXT,chtxt TEXT,ch TEXT,csch TEXT,station TEXT,station_name TEXT,updatetime TEXT)') + except: + "" + db.commit() + self.close_db(db) + def add_chdata(self,bctype, ontv, chtxt, ch, csch, station, station_name,updatetime): + db = self.connect_db(60) + db.execute('insert into chdata values (?,?,?,?,?,?,?,datetime(?))',(bctype,ontv,chtxt,ch,csch,station,station_name,updatetime)) + db.commit() + self.close_db(db) + def select_by_ontv_chdata(self,ontv): + db = self.connect_db(60) + dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ontv = ?",(ontv,)) + ret=dbexe.fetchall() + self.close_db(db) + return ret + def select_by_chtxt_chdata(self,chtxt): + db = self.connect_db(60) + dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE chtxt = ?",(chtxt,)) + ret=dbexe.fetchall() + self.close_db(db) + return ret + def select_by_bctype_chdata(self,bctype): + db = self.connect_db(60) + dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE bctype = ?",(bctype,)) + ret=dbexe.fetchall() + self.close_db(db) + return ret + def select_by_ch_chdata(self,ch): + db = self.connect_db(60) + dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ch = ?",(ch,)) + ret=dbexe.fetchall() + self.close_db(db) + return ret + def select_all_chdata(self): + db = self.connect_db(60) + dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata ") + ret=dbexe.fetchall() + self.close_db(db) + return ret + def select_get_update_chdata(self,dhour): + db = self.connect_db(60) + dbexe=db.execute("SELECT bctype,chtxt FROM chdata WHERE updatetime < datetime(\'now\',\'localtime\',\'-"+dhour+" hours\')") + ret=dbexe.fetchall() + self.close_db(db) + return ret + def update_by_bctype_chdata(self,bctype): + db = self.connect_db(60) + db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE bctype = ?",(bctype,)) + db.commit() + self.close_db(db) + def update_by_bctype_and_chtxt_chdata(self,bctype,chtxt): + db = self.connect_db(60) + db.execute("UPDATE chdata SET updatetime=datetime(\'now\',\'localtime\') WHERE bctype = ? AND chtxt = ?",(bctype,chtxt)) + db.commit() + self.close_db(db) + def add_rectime(self,type="", chtxt="", title="", btime="", etime="", deltatime="", deltaday="", opt=""): - """ - return sqlite3.connect(dbpath,timeout=tout*1000) -def close_db(db): - db.close() -def add_rectime(type="",chtxt="",title="",btime="",etime="",deltatime="",deltaday="",opt=""): - db=connect_db(60) - t=0 - while t<10 + db = self.connect_db(60) + t = 0 + #while t < 10: + # try: + db.execute('insert into rectime (type,chtxt,title,btime,etime,deltatime,deltaday,opt) values (?,?,?,datetime(?),datetime(?),?,?,?)', (type, chtxt, title, btime, etime, deltatime, deltaday, opt)) + # break + # except sqlite3.OperationalError: + # t=t + 1 + # time.sleep(1) + db.commit() + self.close_db(db) + def del_rectime(self,type="", title="", chtxt="", btime=""): + """ + + """ + db=self.connect_db(60) + t=0 + while t < 10 : + try: + db.execute("delete from rectime where type = ? AND title = ? AND chtxt = ? AND btime = datetime(?)", (type, title, chtxt, btime)) + break + except sqlite3.OperationalError: + t=t + 1 + time.sleep(1) + db.commit() + self.close_db(db) + def select_all_rectime(self): + db=self.connect_db(60) + recdata=[] + for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db.execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime"): + ret={} + ret['type']=typet + ret['chtxt']=chtxt + ret['title']=title.encode('utf-8') + ret['btime']=btime + ret['etime']=etime + ret['opt']=opt + if deltatime == None: + deltatime="3" + if deltaday == None: + deltaday="7" + if typet == 'key': + ret['deltatime']=deltatime + elif typet == 'keyevery': + ret['deltatime']=deltatime + ret['deltaday']=deltaday + recdata.append(ret) + self.close_db(db) + return recdata + def select_bytime_rectime(self,dhour): + db=self.connect_db(60) + recdatum=[] + for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db.execute("SELECT type, chtxt, title, DATETIME(btime), DATETIME(etime), deltatime ,deltaday ,opt FROM rectime WHERE btime < datetime(\'now\',\'localtime\',\'+" + dhour + " hours\') AND btime >datetime(\'now\',\'localtime\',\'-" + dhour + " hours\')"): + ret={} + ret['type']=typet + ret['chtxt']=chtxt + ret['title']=title.encode('utf-8') + ret['btime']=btime + ret['etime']=etime + ret['opt']=opt + if deltatime == None or deltatime == "": + deltatime="3" + if deltaday == None or deltaday == "": + deltaday="7" + if typet == 'key': + ret['deltatime']=deltatime + elif typet == 'keyevery': + ret['deltatime']=deltatime + ret['deltaday']=deltaday + recdatum.append(ret) + self.close_db(db) + return recdatum + def delete_old_rectime(self,dhour): + db=self.connect_db(60) + db.execute("DELETE FROM rectime WHERE NOT ( type = ? OR type = ? ) AND btime < datetime(\'now\',\'localtime\',\'-" + dhour + " hours\')", (recdb.REC_MISS_ENCODE, recdb.REC_KEYWORD_EVERY_SOME_DAYS)) + db.commit() + self.close_db(db) + def new_tv(self,bctype): + db=self.connect_db(60) try: - db.execute('insert into rectime values (?,?,?,datetime(?),datetime(?),?,?,?)',(type,chtxt,title,btime,etime,deltatime,deltaday,opt) - break - except sqlite3.OperationalError: - t=t+1 - time.sleep(1) - db.commit() - close_db(db) -def del_rectime(type="",title="",chtxt="",btime=""): - db=connect_db(60) - t=0 - while t<10 + db.execute("delete from tv where bctype = ?", (bctype,)) + except: + "" try: - db.execute("delete from rectime where type = ? AND title = ? AND chtxt = ? AND btime = datetime(?)",(type,title,chtxt,btime)) - break - except sqlite3.OperationalError: - t=t+1 - time.sleep(1) - db.commit() - close_db(db) -def select_all_rectime(): - db=connect_db(60) - recdata=[] - for typet, chtxt, title, btime, etime, deltatime ,deltaday ,opt in db.execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime"): - ret={} - ret['type']=typet - ret['chtxt']=chtxt - ret['title']=title.encode('utf-8') - ret['btime']=btime - ret['etime']=etime - ret['opt']=opt - if deltatime==None: - deltatime="3" - if deltaday==None: - deltaday="7" - if typet=='key': - ret['deltatime']=deltatime - elif typet=='keyevery': - ret['deltatime']=deltatime - ret['deltaday']=deltaday - recdata.append(ret) - close_db(db) - return recdata -def select_bytime_rectime(dhour): - db=connect_db(60) - recdatum=[] - for typet, chtxt, title, btime, etime, deltatime ,deltaday ,opt in db.execute("SELECT type, chtxt, title, DATETIME(btime), DATETIME(etime), deltatime ,deltaday ,opt FROM rectime WHERE btime < datetime(\'now\',\'localtime\',\'+"+dhour+" hours\') AND btime >datetime(\'now\',\'localtime\',\'-"+dhour+" hours\')"): - ret={} - ret['type']=typet - ret['chtxt']=chtxt - ret['title']=title.encode('utf-8') - ret['btime']=btime - ret['etime']=etime - ret['opt']=opt - if deltatime==None or deltatime=="": - deltatime="3" - if deltaday==None or deltaday=="": - deltaday="7" - if typet=='key': - ret['deltatime']=deltatime - elif typet=='keyevery': - ret['deltatime']=deltatime - ret['deltaday']=deltaday - recdatum.append(ret) - close_db(db) - return recdatum -def delete_old_rectime(dhour): - db=connect_db(60) - db.execute("DELETE FROM rectime WHERE NOT ( type = ? OR type = ? ) AND btime < datetime(\'now\',\'localtime\',\'-"+dhour+" hours\')",(recdb.REC_MISS_ENCODE,recdb.REC_KEYWORD_EVERY_SOME_DAYS)) - db.commit() - close_db(db) -def new_tv(bctype): - db=connect_db(60) - try: - db.execute("delete from tv where bctype = ?",bctype) - except: - "" - try: - db.execute('create table tv (bctype TEXT,channel TEXT NOT NULL,start TEXT,stop TEXT,title TEXT,desc TEXT)') - except: - "" - db.commit() - close_db(db) -def add_tv(bctype,channel,start,stop,title,desc): - db=connect_db(60) - t=0 - while t<10 + db.execute('create table tv (bctype TEXT,channel TEXT NOT NULL,start TEXT,stop TEXT,title TEXT,desc TEXT)') + except: + "" + db.commit() + self.close_db(db) + def add_tv(self,bctype, channel, start, stop, title, desc): + db=self.connect_db(60) + t=0 + while t < 10 : + try: + db.execute('insert into tv values (?,?,?,?,?,?)', (bctype, channel, start, stop, title, desc)) + break + except sqlite3.OperationalError: + t=t + 1 + time.sleep(1) + db.commit() + self.close_db(db) + def select_by_title_tv(self,title): + db=self.connect_db(60) + ret=[] + for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""): + btime=start.replace(" +0900","") + btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00" + etime=stop.replace(" +0900","") + etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00" + try: + chtxt=chdb.ontvsearch(ch)['chtxt'] + except: + chtxt="Unknown" + ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime) + self.close_db(db) + return ret + def select_by_time_ngram_tv(self,btime,etime,chtxt): + db=self.connect_db(60) + dbexe="SELECT chdata.chtxt,title,start,stop FROM tv INNER JOIN chdata WHERE chdata.ontv=tv.channel AND start >= ? AND start <= ? AND chdata.chtxt=?" + dbcmd=db.execute(dbexe,(btime,etime,chtxt)) + retall=dbcmd.fetchall() + self.close_db(db) + return retall + def new_ch(self,bctype): + db=self.connect_db(60) try: - db.execute('insert into tv values (?,?,?,?,?,?)',(bctype,channel,start,stop,title,desc)) - break - except sqlite3.OperationalError: - t=t+1 - time.sleep(1) - db.commit() - close_db(db) -def new_ch(bctype): - db=connect_db(60) - try: - db.execute("delete from ch where bctype = ?",bctype) - except: - "" - try: - db.execute('create table ch (bctype TEXT,channel TEXT NOT NULL,display TEXT)') - except: - "" - db.commit() - close_db(db) -def add_ch(bctype,channel,display): - db=connect_db(60) - t=0 - while t<10 + db.execute("delete from ch where bctype = ?", (bctype,)) + except: + "" try: - db.execute('insert into tv values (?,?,?)',(bctype,channel,display)) - break - except sqlite3.OperationalError: - t=t+1 - time.sleep(1) - db.commit() - close_db(db) \ No newline at end of file + db.execute('create table ch (bctype TEXT,channel TEXT NOT NULL,display TEXT)') + except: + "" + db.commit() + self.close_db(db) + def add_ch(self,bctype, channel, display): + db=self.connect_db(60) + t=0 + while t < 10: + try: + db.execute('insert into ch values (?,?,?)', (bctype, channel, display)) + break + except sqlite3.OperationalError: + t=t+1 + time.sleep(1) + db.commit() + self.close_db(db) diff --git a/rec10/trunk/src/epgdb.py b/rec10/trunk/src/epgdb.py index 562e2df..6a9e5a6 100644 --- a/rec10/trunk/src/epgdb.py +++ b/rec10/trunk/src/epgdb.py @@ -3,8 +3,7 @@ # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze import os -import time -import sqlite3 +import rec10d import chdb import datetime import ts2epg @@ -33,7 +32,9 @@ def updatebc(bctype): ts2epg.write(tmppath+"epgdate.xml",chdb.bctypesearch(bctype)['ch']) xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",bctype) break - except: + except Exception,inst: + print type(inst) + print inst i=i+1 def updateall(): update("hisch") @@ -47,64 +48,20 @@ def updateall(): update("bs-nhk-1") def search(titletxt): - dbpath=path+"ch.db" - db=sqlite3.connect(dbpath) - #print dbpath - ret=[] - for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""): - btime=start.replace(" +0900","") - btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00" - etime=stop.replace(" +0900","") - etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00" - try: - chtxt=chdb.ontvsearch(ch)['chtxt'] - except: - chtxt="Unknown" - #print ch - ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime) - db.close() - return ret -def searchtime(titletxt,time,deltatime):#時間以内のものだけを表示 deltatimeはhours - dbpath=path+"ch.db" - db=sqlite3.connect(dbpath) - #print dbpath - ret=[] - deltatime=int(deltatime) - for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""): - btime=start.replace(" +0900","") - btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00" - etime=stop.replace(" +0900","") - etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00" - bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S") - t=datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S") - try: - chtxt=chdb.ontvsearch(ch)['chtxt'] - except: - chtxt="Unknown" - #print ch - dt=bt-t - dt=dt.days*24*60*60+dt.seconds - dt=abs(dt) - if dt0: print title+":"+str(p)+"点" - db.close() ret.append(one) print ret return ret diff --git a/rec10/trunk/src/install.py b/rec10/trunk/src/install.py index 9eda04a..369af5a 100644 --- a/rec10/trunk/src/install.py +++ b/rec10/trunk/src/install.py @@ -3,7 +3,7 @@ # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze import timerec -import chdate +import chdata -chdate +chdata timerec.task() \ No newline at end of file diff --git a/rec10/trunk/src/missed.py b/rec10/trunk/src/missed.py index 2671ca8..761dd50 100755 --- a/rec10/trunk/src/missed.py +++ b/rec10/trunk/src/missed.py @@ -47,56 +47,7 @@ def search_b25(path): else : mode="avi" print title+":"+mode -def search_b25_DB(path): - """ - 検索結果をDBに書き込む。 - """ - db = sqlite3.connect(dbpath) - try: - db.execute('drop table que') - db.commit() - except: - test = "" - try: - db.execute('create table que (title TEXT,que TEXT,status TEXT)') - except: - "" - db.commit() - - b25list=glob.glob(path+"/*.b25") - tslist=glob.glob(path+"/*.ts") - avilist=glob.glob(path+"/*.avi") - 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" - print title+":"+mode path=configreader.getpath("recpath") search_b25(path) \ No newline at end of file diff --git a/rec10/trunk/src/rec10d.py b/rec10/trunk/src/rec10d.py index 53b72e1..0d3d225 100644 --- a/rec10/trunk/src/rec10d.py +++ b/rec10/trunk/src/rec10d.py @@ -7,8 +7,9 @@ import timerec import dbSQLite path=str(os.path.dirname(os.path.abspath(__file__)))+"/" global rec10db -rec10db=dbSQLite(path+"ch.db") +rec10db=dbSQLite.DB_SQLite(path+"ch.db") +if __name__ == "__main__": + timerec.task() -timerec.task() diff --git a/rec10/trunk/src/status b/rec10/trunk/src/status index 55ff910..078ffc8 100644 --- a/rec10/trunk/src/status +++ b/rec10/trunk/src/status @@ -1,3 +1,4 @@ +[tasknum] terec=0 bscsrec=0 ts2avi=0 diff --git a/rec10/trunk/src/tester.py b/rec10/trunk/src/tester.py new file mode 100644 index 0000000..fb7399f --- /dev/null +++ b/rec10/trunk/src/tester.py @@ -0,0 +1,16 @@ +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009 Yukikaze +#import sys +#import os +import chdb +import xml2db +import os +import rec10d +__author__="yukikaze" +__date__ ="$2009/08/01 22:25:13$" +path=str(os.path.dirname(os.path.abspath(__file__)))+"/" +if __name__ == "__main__": + #xml2db.xml2db(path+"epgdate.xml", path+"ch.db","bs") + rec10d.rec10db.update_by_bctype_chdata(u'bs') \ No newline at end of file diff --git a/rec10/trunk/src/xml2db.py b/rec10/trunk/src/xml2db.py index a0198f4..cfe848d 100644 --- a/rec10/trunk/src/xml2db.py +++ b/rec10/trunk/src/xml2db.py @@ -73,7 +73,7 @@ def end_element(name): for row in r: print row """ - "" + print bctype+" epg取り出し終了" flags[name]=0 def char_data(data): global flags,lastflag,xmldate -- 2.11.0