import recdb
import os
import MySQLdb
-import dbSQLite
-path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
class DB_MySQL():
dbname=""
""
db = self.connect_db()
try:
- db[1].execute('CREATE TABLE rectime (id INTEGER PRIMARY KEY,type VARCHAR(10),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(10),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),chtxt VARCHAR(15),ch VARCHAR(10),csch VARCHAR(10),station VARCHAR(20),station_name VARCHAR(30),updatetime DATETIME)')
+ db[1].execute('create table chdata (bctype VARCHAR(15),ontv VARCHAR(30) PRIMARY KEY,chtxt VARCHAR(15),ch VARCHAR(10),csch VARCHAR(10),station VARCHAR(20),station_name VARCHAR(30),updatetime DATETIME)')
except:
""
self.close_db(db)
db=self.connect_db()
recdata=[]
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:
- for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db[1].fetchone():
+ for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in dbl:
ret={}
ret['type']=typet
ret['chtxt']=chtxt
def select_bytime_rectime(self,dminutes):
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 < 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 )")
+ dbl=db[1].fetchall()
+ self.close_db(db)
+ #print dbl
if dbr > 0:
- for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db[1].fetchone():
+ for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in dbl:
ret={}
ret['type']=typet
ret['chtxt']=chtxt
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()
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 db[1].fetchone():
+ 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","")
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()
予定によって子プロセスを生成し処理する。
"""
recdb.delete_old("6")
- tasks=recdb.getnow("1")
+ tasks=recdb.getnow("2")
+ #print tasks
inum=recdb.countRecNow("1")
print "now-rectask"
print "inum:"+str(inum)+"bscsrec:"+str(status.getBSCSRecording())+"terec:"+str(status.getTERecording())
sys.exit(0)
for task in tasks:
+ #print task
try:
chtxt=task['chtxt']
except:
titlet=recdata[1]
btimet=recdata[2]
etimet=recdata[3]
- bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
- et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
+ bt=datetime.datetime.strptime(btimet,"%Y-%m-%d %H:%M:%S")
+ et=datetime.datetime.strptime(etimet,"%Y-%m-%d %H:%M:%S")
btimet=bt.strftime("%Y-%m-%d %H:%M:%S")
etimet=et.strftime("%Y-%m-%d %H:%M:%S")
if chtxt!="":
try:
- recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime)
+ recdb.del_reckey(recdb.REC_KEYWORD, title, chtxt, btime)
recdb.rec_reckey(recdb.REC_FINAL_RESERVE, titlet, chtxtt, btimet, etimet, opt)
except Exception,inst:
print type(inst)