# Rec10 TS Recording Tools
# Copyright (C) 2009 Yukikaze
import recdb
-import os
import MySQLdb
import dbSQLite
""
db = self.connect_db()
try:
- db[1].execute('CREATE TABLE rectime (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,type VARCHAR(20),chtxt VARCHAR(20),title VARCHAR(100),btime DATETIME,etime DATETIME,deltatime VARCHAR(5),deltaday VARCHAR(5),opt VARCHAR(20),UNIQUE uni (type,chtxt,title,btime,deltaday))')
+ db[1].execute('\
+ CREATE TABLE rectime \
+ (\
+ id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\
+ type VARCHAR(20),\
+ chtxt VARCHAR(20),\
+ title VARCHAR(100),\
+ btime DATETIME,\
+ etime DATETIME,\
+ deltatime VARCHAR(5),\
+ deltaday VARCHAR(5),\
+ opt VARCHAR(20),\
+ UNIQUE uni (type,chtxt,title,btime,deltaday)\
+ )')
except:
""
self.new_tv("")
except:
""
try:
- db[1].execute('create table chdata (bctype VARCHAR(15),ontv VARCHAR(30) PRIMARY KEY,chtxt VARCHAR(15),ch VARCHAR(20),csch VARCHAR(20),station VARCHAR(20),station_name VARCHAR(30),updatetime DATETIME,status TINYINT)')
+ db[1].execute('\
+ CREATE TABLE chdata \
+ (\
+ bctype VARCHAR(15),\
+ ontv VARCHAR(30) PRIMARY KEY,\
+ chtxt VARCHAR(15),\
+ ch VARCHAR(20),\
+ csch VARCHAR(20),\
+ station VARCHAR(20),\
+ station_name VARCHAR(30),\
+ updatetime DATETIME,\
+ status TINYINT\
+ )')
except:
""
self.close_db(db)
def add_chdata(self,bctype, ontv, chtxt, ch, csch, station, station_name,updatetime):
db = self.connect_db()
- db[1].execute('insert into chdata values (%s,%s,%s,%s,%s,%s,%s,%s,%s)',(bctype,ontv,chtxt,ch,csch,station,station_name,updatetime,"1"))
+ db[1].execute('\
+ INSERT INTO chdata \
+ VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)',\
+ (bctype,ontv,chtxt,ch,csch,station,station_name,updatetime,"1"))
self.close_db(db)
def select_by_ontv_chdata(self,ontv):
db = self.connect_db()
- dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE ontv = %s",(ontv,))
+ dbexe=db[1].execute("\
+ SELECT bctype,ontv,chtxt,ch,csch,updatetime \
+ FROM chdata \
+ WHERE ontv = %s",\
+ (ontv,))
ret=[]
dls=[]
if dbexe>0:
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,))
+ dbexe=db[1].execute("\
+ SELECT bctype,ontv,chtxt,ch,csch,updatetime \
+ FROM chdata \
+ WHERE chtxt = %s",\
+ (chtxt,))
ret=[]
dls=[]
if dbexe>0:
return ret
def select_by_bctype_chdata(self,bctype):
db = self.connect_db()
- dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime,status 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:
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,))
+ dbexe=db[1].execute("\
+ SELECT \
+ bctype,ontv,chtxt,ch,csch,updatetime \
+ FROM chdata \
+ WHERE ch = %s",\
+ (ch,))
ret=[]
dls=[]
if dbexe>0:
return ret
def select_all_chdata(self):
db = self.connect_db()
- dbexe=db[1].execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata ")
+ dbexe=db[1].execute("\
+ SELECT bctype,ontv,chtxt,ch,csch,updatetime \
+ FROM chdata \
+ ")
ret=[]
dls=[]
if dbexe>0:
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 = 1 ) OR status > 1 ORDER BY status DESC")
+ dbexe=db[1].execute("SELECT bctype,chtxt,status FROM chdata \
+ WHERE \
+ ( \
+ updatetime < DATE_SUB(now(),INTERVAL "+dhour+" HOUR) \
+ AND \
+ status = 1 \
+ ) \
+ OR \
+ status > 1 \
+ ORDER BY status DESC")
ret=[]
#print dbexe
if dbexe>0:
return ret
def update_by_bctype_chdata(self,bctype):
db = self.connect_db()
- db[1].execute("UPDATE chdata SET updatetime=now() , status = 1 WHERE bctype = %s",(bctype,))
+ db[1].execute("\
+ UPDATE chdata \
+ SET \
+ updatetime=now() , \
+ status = 1 \
+ WHERE bctype = %s",(bctype,))
self.close_db(db)
def update_by_bctype_and_chtxt_chdata(self,bctype,chtxt):
db = self.connect_db()
- db[1].execute("UPDATE chdata SET updatetime=now() , status = 1WHERE bctype = %s AND chtxt = %s",(bctype,chtxt))
+ db[1].execute("\
+ UPDATE chdata \
+ SET \
+ updatetime=now() , \
+ status = 1\
+ WHERE bctype = %s AND chtxt = %s",(bctype,chtxt))
self.close_db(db)
def update_status_by_bctype_chdata(self,bctype,status):
db = self.connect_db()
- db[1].execute("UPDATE chdata SET status=%s WHERE bctype = %s",(status,bctype))
+ db[1].execute("\
+ UPDATE chdata \
+ SET \
+ status=%s \
+ WHERE bctype = %s",\
+ (status,bctype)\
+ )
self.close_db(db)
def add_rectime(self,type="", chtxt="", title="", btime="", etime="", deltatime="", deltaday="", opt=""):
db = self.connect_db()
- db[1].execute('INSERT IGNORE into rectime (type,chtxt,title,btime,etime,deltatime,deltaday,opt) values (%s,%s,%s,%s,%s,%s,%s,%s)', (type, chtxt, title, btime, etime, deltatime, deltaday, opt))
+ db[1].execute('\
+ INSERT IGNORE into rectime \
+ (type,chtxt,title,btime,etime,deltatime,deltaday,opt) \
+ values (%s,%s,%s,%s,%s,%s,%s,%s)', \
+ (type, chtxt, title, btime, etime, deltatime, deltaday, opt))
##db.commit()
self.close_db(db)
def del_rectime(self,type="", title="", chtxt="", btime=""):
"""
db=self.connect_db()
- db[1].execute("delete from rectime where type = %s AND title = %s AND chtxt = %s AND btime = %s", (type, title, chtxt, btime))
+ db[1].execute("\
+ DELETE FROM rectime \
+ WHERE type = %s AND title = %s AND chtxt = %s AND btime = %s", \
+ (type, title, chtxt, btime))
#db.commit()
self.close_db(db)
def select_all_rectime(self):
db=self.connect_db()
recdata=[]
- dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime")
+ dbr=db[1].execute("\
+ SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt \
+ FROM rectime")
dbl=db[1].fetchall()
self.close_db(db)
if dbr>0:
db=self.connect_db()
recdatum=[]
#dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )")
- dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime BETWEEN DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )")
+ dbr=db[1].execute("SELECT \
+ type, chtxt, title, btime, etime, deltatime ,deltaday ,opt \
+ FROM rectime \
+ WHERE btime BETWEEN DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND \
+ DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )")
dbl=db[1].fetchall()
self.close_db(db)
#print dbl
return recdatum
def delete_old_rectime(self,dhour):
db=self.connect_db()
- db[1].execute("DELETE FROM rectime WHERE NOT ( type = %s OR type = %s ) AND btime < DATE_SUB(now(),INTERVAL "+dhour+" HOUR )", (recdb.REC_MISS_ENCODE, recdb.REC_KEYWORD_EVERY_SOME_DAYS))
+ db[1].execute("\
+ DELETE FROM rectime \
+ WHERE \
+ NOT ( type = %s OR type = %s ) \
+ AND \
+ btime < DATE_SUB(now(),INTERVAL "+dhour+" HOUR )", \
+ (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()
try:
- db[1].execute("delete from tv where bctype = %s", (bctype,))
+ db[1].execute("\
+ DELETE FROM tv \
+ WHERE bctype = %s", \
+ (bctype,))
except:
""
try:
- db[1].execute("create table tv (bctype VARCHAR(20),channel VARCHAR(100) NOT NULL,start VARCHAR(30),stop VARCHAR(30),title VARCHAR(100),exp VARCHAR(200),UNIQUE unitv(bctype,channel,start,stop,title))")
+ db[1].execute("\
+ CREATE TABLE tv \
+ (\
+ bctype VARCHAR(20),\
+ channel VARCHAR(100) NOT NULL,\
+ start VARCHAR(30),\
+ stop VARCHAR(30),\
+ title VARCHAR(100),\
+ exp VARCHAR(200),\
+ UNIQUE unitv(bctype,channel,start,stop,title)\
+ )")
except:
""
#db.commit()
self.close_db(db)
def add_tv(self,bctype, channel, start, stop, title, desc):
db=self.connect_db()
- db[1].execute('INSERT IGNORE INTO tv VALUES (%s,%s,%s,%s,%s,%s)', (bctype, channel, start, stop, title, desc))
+ db[1].execute('\
+ INSERT IGNORE INTO tv \
+ VALUES (%s,%s,%s,%s,%s,%s)', \
+ (bctype, channel, start, stop, title, desc))
#db.commit()
self.close_db(db)
def add_multi_tv(self,tvlists):
tvlists is (bctype,channel,start,stop,title,desc) lists.
"""
db=self.connect_db()
- db[1].executemany('INSERT IGNORE INTO tv (bctype,channel,start,stop,title,exp) values(%s,%s,%s,%s,%s,%s)', tvlists)
+ db[1].executemany('\
+ INSERT IGNORE INTO tv \
+ (bctype,channel,start,stop,title,exp) \
+ values(%s,%s,%s,%s,%s,%s)', \
+ tvlists)
#db.commit()
self.close_db(db)
def select_by_time_ngram_tv(self,btime,etime,chtxt):
db=self.connect_db()
- dbexe="SELECT chdata.chtxt,title,start,stop FROM tv INNER JOIN chdata WHERE chdata.ontv=tv.channel AND start >= %s AND start <= %s AND chdata.chtxt=%s"
+ dbexe="\
+ SELECT \
+ chdata.chtxt,title,start,stop \
+ FROM tv \
+ INNER JOIN chdata \
+ WHERE chdata.ontv=tv.channel \
+ AND \
+ start >= %s \
+ AND \
+ start <= %s \
+ AND \
+ chdata.chtxt=%s"
dbcmd=db[1].execute(dbexe,(btime,etime,chtxt))
retall=[]
if dbcmd>0:
def new_ch(self,bctype):
db=self.connect_db()
try:
- db[1].execute("delete from ch where bctype = %s", (bctype,))
+ db[1].execute("DELETE FROM ch WHERE bctype = %s", (bctype,))
except:
""
try:
- db[1].execute('create table ch (bctype VARCHAR(20),channel VARCHAR(20) NOT NULL,display VARCHAR(100),UNIQUE unich(bctype,channel))')
+ db[1].execute('\
+ CREATE TABLE ch \
+ (\
+ bctype VARCHAR(20),\
+ channel VARCHAR(20) NOT NULL,\
+ display VARCHAR(100),\
+ UNIQUE unich(bctype,channel)\
+ )')
except:
""
#db.commit()
for db in dbl:
self.add_rectime(db['type'],db['chtxt'],db['title'],db['btime'],db['etime'],db['deltatime'],db['deltaday'],db['opt'])
-""" def select_by_title_tv(self,title):
- db=self.connect_db()
- ret=[]
- dbr=db[1].execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\"")
- dbl=db[1].fetchall()
- self.close_db(db)
- if dbr>0:
- for ch, title, start, stop in dbl:
- 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)
- return ret"""
\ No newline at end of file
if i>1:
break
sys.exit()
- """if len(update)>0 and status.getEPGUpdating()==0:
- #status.setEPGUpdating(1)
- print "番組表を更新"
- #print update
- status.setEPGUpdating(1)
- pid=os.fork()
- if pid!=0:#親プロセスの場合
- ""
- else:#子プロセスの場合 アップデートを行って終了
- i=0
- for bctype in update:
- time.sleep(1)
- print bctype
- epgdb.updatebc(bctype)
- update=chdb.update()
- i=i+1
- print update
- if i>10:
- break
- status.setEPGUpdating(0)
- sys.exit()"""
for task in tasks:
#print task
try:
tnow=datetime.datetime.now()
dtt=bt-tnow
dt=dtt.days*24*60*60+dtt.seconds
-
+ #print title+str(dt)
if task["type"]==recdb.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt
- print dt
if (dt<58*60 and dt>20*60):
pid=os.fork()
if pid!=0:#親プロセスの場合
else:#子プロセスの場合 アップデートを行って終了
bctypet=chdb.chtxtsearch(chtxt)['bctype']
chdatat=rec10d.rec10db.select_by_bctype_chdata(bctypet)
- dt1=datetime.datetime.now()-datetime.datetime.strptime(chdatat[0][5],"%Y-%m-%d %H:%M:%S")
+ dt1=datetime.datetime.strptime(chdatat[0][5],"%Y-%m-%d %H:%M:%S")-datetime.datetime.now()
dt1=dt1.days*24*60*60+dt1.seconds
+ #print "oikake search:"+str(dt1)
if dt1<60*60:
recdata=epgdb.searchtime2(title.decode('utf-8'),btime,"5",chtxt)
chtxtn=recdata[0]
if rec10d.rec10db.select_by_bctype_chdata(bctypet)[0][6]!="0":
rec10d.rec10db.update_status_by_bctype_chdata(bctypet,"3")
sys.exit()
- """cht=chdb.chtxtsearch(chtxt)['bctype']
- if cht.find('te')!=-1:
- cht='te'
- else:
- cht='bscs'
- bctypetemp=chdb.chtxtsearch(chtxt)['bctype']
- if cht=='bscs':
- gettaskbscs=recdb.countRecNow_minutes_BSCS("10")
- getnowbscs=status.getBSCSRecording()
- bscs=getnowbscs+gettaskbscs
- if bscs <2 and status.getEPGUpdating()!=1:
- print "now(bscs):"+str(getnowbscs)+" task(bscs):"+str(gettaskbscs)
- status.setEPGUpdating(1)
- rec10d.rec10db.update_status_by_bctype_chdata(bctype,"0")
- epgdb.updatebc(bctypetemp)
- time.sleep(10)
- isUpdate=1
- status.setEPGUpdating(0)
- else:
- isUpdate=0
- if cht=="te":
- gettaskte=recdb.countRecNow_minutes_TE("10")
- getnowte=status.getTERecording()
- te=getnowte+gettaskte
- if te <2 and status.getEPGUpdating()!=1:
- print "now(te):"+str(getnowte)+" task(te):"+str(gettaskte)
- status.setEPGUpdating(1)
- epgdb.updatebc(bctypetemp)
- time.sleep(10)
- status.setEPGUpdating(0)
- isUpdate=1
- else:
- isUpdate=0
- if isUpdate:
- recdata=epgdb.searchtime2(title.decode('utf-8'),btime,"5",chtxt)
- chtxtn=recdata[0]
- titlen=recdata[1]
- btimen=recdata[2]
- etimen=recdata[3]
- bt=datetime.datetime.strptime(btimen,"%Y-%m-%d %H:%M:%S")
- et=datetime.datetime.strptime(etimen,"%Y-%m-%d %H:%M:%S")
- btimen=bt.strftime("%Y-%m-%d %H:%M:%S")
- etimen=et.strftime("%Y-%m-%d %H:%M:%S")
- if chtxt!="":
- try:
- recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime)
- recdb.rec_reckey(recdb.REC_FINAL_RESERVE, titlen, chtxtn, btimen, etimen, opt)
- except Exception,inst:
- print type(inst)
- print inst
- else:
- print "nothing match"
- else:
- ""
- sys.exit()"""
-
- elif dt<=10*60:
+ elif dt<=20*60:
try:
recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime)
recdb.rec_reckey(recdb.REC_FINAL_RESERVE, title, chtxt, btime, etime, opt)