X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=rec10%2Ftrunk%2Fsrc%2Fepgdb.py;h=77e480e61d51df7e7fe885724bd2db180bdf3cf2;hb=2d0fd598eec8b926e8e5662221f3f4a07c9dd72e;hp=40850ef15f49ca952df1adc33d9d7231d5ccd1e6;hpb=6bd7a33e3cfdbe37ee1cc3025ac586ef1280de7f;p=rec10%2Frec10-git.git diff --git a/rec10/trunk/src/epgdb.py b/rec10/trunk/src/epgdb.py index 40850ef..77e480e 100644 --- a/rec10/trunk/src/epgdb.py +++ b/rec10/trunk/src/epgdb.py @@ -2,83 +2,93 @@ # coding: UTF-8 # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze +import datetime import os -import sqlite3 +import shutil + import chdb -import datetime +import n_gram +import rec10d import ts2epg import xml2db -path=str(os.path.dirname(os.path.abspath(__file__)))+"/" -tmppath=path +import configreader +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getpath("tmp")+"/" def update(chtxt): print chtxt - tnow=datetime.datetime.now() + tnow = datetime.datetime.now() try: - lastup=datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'],"%Y-%m-%d %H:%M:%S") + lastup = datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S") except: - lastup=datetime.datetime.strptime("2009-04-01 00:00:00","%Y-%m-%d %H:%M:%S") - dt=tnow-lastup - dt=dt.days*24*60+dt.seconds - if dt>2*60*60: - ts2epg.write(tmppath+"epgdate.xml",chdb.chtxtsearch(chtxt)['ch']) - xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",chdb.chtxtsearch(chtxt)['bctype']) + lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S") + dt = tnow-lastup + dt = dt.days * 24 * 60 + dt.seconds + if dt > 2 * 60 * 60: + ts2epg.write(tmppath + chtxt + "epgdate.xml", chdb.chtxtsearch(chtxt)['ch']) + xml2db.xml2db(tmppath + chtxt + "epgdate.xml", chdb.chtxtsearch(chtxt)['bctype']) def updatebc(bctype): - bctypel=chdb.bctypesearch(bctype) + bctypel = chdb.bctypesearch(bctype) print bctypel - ts2epg.write(tmppath+"epgdate.xml",chdb.bctypesearch(bctype)['ch']) - xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",bctype) -def updateall(): - update("hisch") - update("nhk-k") - update("nhk-s") - update("me-tere") - update("cbc") - update("aichi") - update("toukai") - update("chukyo") - 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 dt 0: + p = p + dt + print dt + if p > tempt: + one = [chtxtt, title.encode('utf-8'), btime, etime,exp.encode('UTF-8'),longexp.encode('UTF-8'),category.encode('UTF-8')] + tempt = p + if p > 0: + print title + ":" + str(p) + "点" + ret = one + print ret return ret - +def searchtime_auto(keytxt, timet, deltatime): + time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") + ret = [] + deltatime = int(deltatime) + beforetime = time.strftime("%Y%m%d%H%M%S") + aftertime = time + datetime.timedelta(hours=deltatime) + aftertime = aftertime.strftime("%Y%m%d%H%M%S") + d = rec10d.rec10db.select_by_time_auto_suggest_tv(keytxt,beforetime, aftertime) + for chtxtt, title, start, stop ,exp,longexp,category in d: + btime = start + btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00" + etime = stop + etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" + ret.append([chtxtt, title.encode('utf-8'), btime, etime,exp.encode('UTF-8'),longexp.encode('UTF-8'),category.encode('UTF-8')]) + return ret \ No newline at end of file