From 38498bccb9ef45b9c967ab239560771c6a86e6c1 Mon Sep 17 00:00:00 2001 From: gn64_jp Date: Mon, 24 Aug 2009 02:38:09 +0000 Subject: [PATCH] implement personal epg updating(beta). git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@130 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/dbMySQL.py | 42 ++++++++++++++++++++++++++++++++++-------- rec10/trunk/src/dbSQLite.py | 4 ++-- rec10/trunk/src/epgdb.py | 3 ++- rec10/trunk/src/timerec.py | 6 ++++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/rec10/trunk/src/dbMySQL.py b/rec10/trunk/src/dbMySQL.py index 3cd40ee..dd2c663 100644 --- a/rec10/trunk/src/dbMySQL.py +++ b/rec10/trunk/src/dbMySQL.py @@ -65,47 +65,73 @@ class DB_MySQL: db = self.connect_db() dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ontv = %s",(ontv,)) ret=[] + dls=[] if dbexe>0: - ret=db[1].fetchall() + dls=db[1].fetchall() self.close_db(db) + for dl in dls: + r=list(dl) + r[5]=r[5].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) return ret def select_by_chtxt_chdata(self,chtxt): db = self.connect_db() dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE chtxt = %s",(chtxt,)) ret=[] + dls=[] if dbexe>0: - ret=db[1].fetchall() + dls=db[1].fetchall() self.close_db(db) + for dl in dls: + r=list(dl) + r[5]=r[5].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) return ret def select_by_bctype_chdata(self,bctype): db = self.connect_db() - dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE bctype = %s",(bctype,)) + dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime,status FROM chdata WHERE bctype = %s",(bctype,)) ret=[] + dls=[] if dbexe>0: - ret=db[1].fetchall() + dls=db[1].fetchall() self.close_db(db) + for dl in dls: + #print dl + r=list(dl) + r[5]=r[5].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) return ret def select_by_ch_chdata(self,ch): db = self.connect_db() dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ch = %s",(ch,)) ret=[] + dls=[] if dbexe>0: - ret=db[1].fetchall() + dls=db[1].fetchall() self.close_db(db) + for dl in dls: + r=list(dl) + r[5]=r[5].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) return ret def select_all_chdata(self): db = self.connect_db() dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata ") ret=[] + dls=[] if dbexe>0: - ret=db[1].fetchall() + dls=db[1].fetchall() self.close_db(db) + for dl in dls: + r=list(dl) + r[5]=r[5].strftime("%Y-%m-%d %H:%M:%S") + ret.append(r) return ret def select_get_update_chdata(self,dhour): db = self.connect_db() - dbexe=db[1].execute("SELECT bctype,chtxt,status FROM chdata WHERE updatetime < DATE_SUB(now(),INTERVAL "+dhour+" HOUR) AND status > 0 ORDER BY status DESC") + dbexe=db[1].execute("SELECT bctype,chtxt,status FROM chdata WHERE ( updatetime < DATE_SUB(now(),INTERVAL "+dhour+" HOUR) AND status = 0 ) OR status > 1 ORDER BY status DESC") ret=[] - print dbexe + #print dbexe if dbexe>0: ret=db[1].fetchall() self.close_db(db) diff --git a/rec10/trunk/src/dbSQLite.py b/rec10/trunk/src/dbSQLite.py index b055a1b..cb97bd9 100644 --- a/rec10/trunk/src/dbSQLite.py +++ b/rec10/trunk/src/dbSQLite.py @@ -60,7 +60,7 @@ class DB_SQLite: return ret def select_by_bctype_chdata(self,bctype): db = self.connect_db(480) - dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE bctype = ?",(bctype,)) + dbexe=db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime,status FROM chdata WHERE bctype = ?",(bctype,)) ret=dbexe.fetchall() self.close_db(db) return ret @@ -78,7 +78,7 @@ class DB_SQLite: return ret def select_get_update_chdata(self,dhour): db = self.connect_db(480) - dbexe=db.execute("SELECT bctype,chtxt,status FROM chdata WHERE updatetime < datetime(\'now\',\'localtime\',\'-"+dhour+" hours\') AND status > 0 ORDER BY status DESC") + dbexe=db.execute("SELECT bctype,chtxt,status FROM chdata WHERE ( updatetime < datetime(\'now\',\'localtime\',\'-"+dhour+" hours\') AND status > 0 ) OR status > 1 ORDER BY status DESC") ret=dbexe.fetchall() self.close_db(db) return ret diff --git a/rec10/trunk/src/epgdb.py b/rec10/trunk/src/epgdb.py index 6f0c433..8a6eef9 100644 --- a/rec10/trunk/src/epgdb.py +++ b/rec10/trunk/src/epgdb.py @@ -41,7 +41,8 @@ def updatebc(bctype): print type(inst) print inst xml2db.xml2db(tmppath+bctype+"epgdate.bak.xml",bctype) - rec10d.rec10db.update_status_by_bctype_chdata(bctype,"2") + if rec10d.rec10db.select_by_bctype_chdata(bctypet)[0][6]!="0": + rec10d.rec10db.update_status_by_bctype_chdata(bctype,"2") def updatebc_bak(bctype): """ update epg data by .bak file diff --git a/rec10/trunk/src/timerec.py b/rec10/trunk/src/timerec.py index ccfc705..b7a5279 100644 --- a/rec10/trunk/src/timerec.py +++ b/rec10/trunk/src/timerec.py @@ -32,6 +32,7 @@ def task(): #if inum+status.getBSCSRecording()+status.getTERecording() < 2: update=chdb.update() + print update print "番組表更新処理" if len(update)>0: pid=os.fork() @@ -117,7 +118,7 @@ def task(): else:#子プロセスの場合 アップデートを行って終了 bctypet=chdb.chtxtsearch(chtxt)['bctype'] chdatat=rec10d.rec10db.select_by_bctype_chdata(bctypet) - dt1=datetime.datetime.now()-datetime.datetime.strptime(chdatat[5],"%Y-%m-%d %H:%M:%S") + dt1=datetime.datetime.now()-datetime.datetime.strptime(chdatat[0][5],"%Y-%m-%d %H:%M:%S") dt1=dt1.days*24*60*60+dt1.seconds if dt1<60*60: recdata=epgdb.searchtime2(title.decode('utf-8'),btime,"5",chtxt) @@ -140,6 +141,7 @@ def task(): print "nothing match" else: rec10d.rec10db.update_status_by_bctype_chdata(bctypet,"3") + sys.exit() """cht=chdb.chtxtsearch(chtxt)['bctype'] if cht.find('te')!=-1: cht='te' @@ -330,4 +332,4 @@ def task(): et=et+datetime.timedelta(seconds=600) btime=bt.strftime("%Y-%m-%d %H:%M:%S") etime=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime,etime,opt) \ No newline at end of file + recdb.rec_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime,etime,opt) -- 2.11.0