3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
11 path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
15 db=sqlite3.connect(dbpath)
16 recdata="\"id\",\"type\",\"chtxt\",\"title\",\"btime\",\"etime\",\"deltaday\",\"opt\"\n"
17 recdata="id,type,chtxt,title,btime,etime,deltaday,opt\n"
18 for id, typet, chtxt, title, btime, etime, deltatime ,deltaday ,opt in db.execute("SELECT id, type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime"):
29 elif typet=="keyevery":
39 btime=btime.replace("-","/")
40 etime=etime.replace("-","/")
41 if btime[0:5]==etime[0:5]:
43 s="\""+str(id)+"\",\""+typet+"\",\""+chtxt+"\",\""+title+"\",\""+btime+"\",\""+etime+"\",\""+deltaday+"\",\""+opt+"\"\n"
44 s=str(id)+","+typet+","+chtxt+","+title+","+btime+","+etime+","+deltaday+","+opt+"\n"
46 f=open("recdatum.csv","w")
50 db=sqlite3.connect(dbpath)
52 for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata"):
54 for bctype,channel,display in db.execute("SELECT bctype,channel,display FROM ch WHERE channel=\""+ontv+"\""):
56 chopt=chopt+"<option value="+chtxt+">"+display+"</option>\n "
59 def reserv(type,keyword,chtxt,btime,etime,deltatime,opt,deltaday):
62 db=sqlite3.connect(dbpath)
65 dbexe="SELECT chdata.bctype,rectime.chtxt,rectime.title FROM rectime INNER JOIN chdata ON rectime.chtxt=chdata.chtxt"
66 #dbexe="SELECT bctype,chtxt,title FROM rectime INNER JOIN chdata ON rectime.chtxt=chdata.chtxt"
68 dbexe=dbexe+" WHERE NOT( ( rectime.etime <= "+bt+" ) OR ( rectime.btime >= "+et+" ) )"
69 for bctypet, chtxtt, titlet in db.execute(dbexe):
70 if bctypet.find("cs")>-1:
72 elif bctypet.find("bs")>-1:
74 elif bctypet.find("te")>-1:
78 for bctypet, chtxtt in db.execute("SELECT bctype,chtxt FROM chdata WHERE chtxt=\'"+chtxt+"\'"):
80 if bctype.find("cs")>-1:
82 elif bctype.find("bs")>-1:
84 elif bctype.find("te")>-1:
86 if MaxS>-1 and MaxT>-1:
87 recline="\""+type+"\",\""+chtxt+"\",\""+keyword+"\",datetime(\""+btime+"\"),datetime(\""+etime+"\"),\""+deltatime+"\",\""+opt+"\",\""+deltaday+"\""
89 db.execute('insert into rectime ("type","chtxt","title","btime","etime","deltatime","opt","deltaday") values ('+recline+')')
95 def station2chtxt(station):
96 db=sqlite3.connect(dbpath)
98 for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE station=\""+station+"\""):
102 def station_name2chtxt(station):
103 db=sqlite3.connect(dbpath)
105 for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE station_name=\""+station+"\""):
109 def readHtmlSrcSimple():
110 f = open(path+'rswi.htm')
115 def readRecFinisSimple():
116 f = open(path+'fin.htm')
120 def readRecFinisOver():
121 f = open(path+'finover.htm')
125 def readRecSchedule():
126 f = open(path+'schedule.htm')
139 if f.getfirst('mode')=="schedule":
143 if f.getfirst('station_name'):
144 station=f.getfirst('station_name')
145 chtxt=station_name2chtxt(station)
146 if f.getfirst('station'):
147 station=f.getfirst('station')
148 chtxt=station2chtxt(station)
150 if f.getfirst('type'):
151 type=f.getfirst('type')
152 if f.getfirst('title'):
153 title=f.getfirst('title')
154 if f.getfirst('chtxt'):
155 chtxt=f.getfirst('chtxt')
156 if f.getfirst('btime'):
157 btime=f.getfirst('btime')
158 bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
159 if f.getfirst('etime'):
160 etime=f.getfirst('etime')
161 et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
164 dt=delt.days*24*60*60+delt.seconds
166 dd=datetime.timedelta(days=1)
168 etime=et.strftime("%Y-%m-%d %H:%M:%S")
170 d1=datetime.datetime(bt.year,0,0)
171 d2=datetime.datetime(bt.year+1,0,0)
174 etime=et.strftime("%Y-%m-%d %H:%M:%S")
177 if f.getfirst('size'):
178 size=f.getfirst('size')
180 if f.getfirst('opts'):
181 opts=f.getfirst('opts')
183 if f.getfirst('deltahour',""):
184 deltahour=f.getfirst('deltahour',"")
186 if f.getfirst('deltaday',""):
187 deltaday=f.getfirst('deltaday',"")
189 if f.getfirst('exec',""):
190 exect=f.getfirst('exec',"")
192 htmdate= readHtmlSrcSimple()
193 htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
195 htmdate=htmdate.replace("<!--btime-value//-->",btime)
196 htmdate=htmdate.replace("<!--etime-value//-->",etime)
197 htmdate=htmdate.replace("<!--type-value//-->",type)
198 htmdate=htmdate.replace("<!--ch-value//-->",chtxt)
199 htmdate=htmdate.replace("<!--title-value//-->",title)
200 htmdate=htmdate.replace("<!--size-value//-->",size)
201 htmdate=htmdate.replace("<!--opts-value//-->",opts)
203 if (chtxt != "")and(title != "")and(btime!="")and(etime!="")and(opts!="")and(exect=="yes"):
204 restxt=reserv(type, title, chtxt, btime, etime, deltahour, opts, deltaday)
206 htmdate=readRecFinisSimple()
208 htmdate=readRecFinisOver()
211 if exect=="schedule":
212 htmdate=readRecSchedule()