# Rec10 TS Recording Tools
# Copyright (C) 2009 Yukikaze
import cgi
-#import cgitb;cgitb.enable()
+import cgitb;cgitb.enable()
import rec10web_dbMySQL
import rec10web_dbSQLite
import os
import rec10web_dbSQLite
import ConfigParser
import time
+
path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
confp=ConfigParser.SafeConfigParser()
Conf='config.ini'
confp.read(path+Conf)
+global f
+f=cgi.FieldStorage()
def getpath(string):
global confp
return confp.get('path',string)
def getdbpath(string):
global confp
return confp.get('db',string)
-
def getdb():
retdb=""
if getdbpath('db')=='MySQL':
def edit_date(id):
ret=database.select_by_id_rectime(id)
return ret[0]
-
def reserv_recday(keyword,chtxt,btime,etime,deltatime,opt,deltaday,day):
"""
dayは月曜日を1日曜日を7とした数字
dls=database.schedule_rectime(btime,etime)
print dls
times=[]
+ btd=datetime.datetime(*time.strptime(btime,"%Y-%m-%d %H:%M:%S")[:-3])
+ etd=datetime.datetime(*time.strptime(etime,"%Y-%m-%d %H:%M:%S")[:-3])
for dl in dls:
- times.append(datetime.datetime(*time.strptime(dl[4],"%Y-%m-%d %H:%M:%S")[:-3]))
- times.append(datetime.datetime(*time.strptime(dl[5],"%Y-%m-%d %H:%M:%S")[:-3]))
+ dd1=datetime.datetime(*time.strptime(dl[4],"%Y-%m-%d %H:%M:%S")[:-3])
+ dd2=datetime.datetime(*time.strptime(dl[5],"%Y-%m-%d %H:%M:%S")[:-3])
+ if dd1<btd:
+ dd1=btd
+ if dd2>etd:
+ dd2=etd
+ times.append(dd1)
+ times.append(dd2)
print times
times=list(set(times))
print times
return rett
def station2chtxt(station):
ret=""
- for bctype, ontv, chtxt, ch, csch ,updatetime in database.select_by_station_chdata(station):
- ret=chtxt
- return ret
-def station_name2chtxt(station):
- ret=""
- for bctype, ontv, chtxt, ch, csch ,updatetime in database.select_by_station_name_chdata(station):
- ret=chtxt
+ sta=database.select_by_station_iepg(station):
+ if len(sta)>0:
+ ret=sta[0][1]
+ else:
+ ret="n\/a"
return ret
def readHtmlSrcSimple():
f = open(path+'rswi.htm')
ret=f.read()
f.close()
return ret
+def readiEPGadd():
+ f = open(path+'iepg_add.htm')
+ ret=f.read()
+ f.close()
+ return ret
+def readiEPGfin():
+ f = open(path+'iepg_fin.htm')
+ ret=f.read()
+ f.close()
+ return ret
+def readiEPGshow():
+ f = open(path+'iepg_show.htm')
+ ret=f.read()
+ f.close()
+ return ret
+def mode_iepg_add(station):
+ htmdate=readiEPGadd()
+ htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
+ htmdate=htmdate.replace("<!--ch-value//-->","")
+ htmdate=htmdate.replace("<!--iepg_title-value//-->",station)
+ return htmdate
+def mode_iepg_fin():
+ htmdate=readiEPGfin()
+ return htmdate
+def mode_iepg_show():
+ htmdate=readiEPGshow()
+ lsts=database.select_all_iepg()
+ s=""
+ for lst in lsts:
+ s=s+"{name:\""+lst[0]+"\",chtxt:\""+lst[1]+"\"},\n"
+ return htmdate
+def mode_schedule():
+ htmdate=readRecSchedule()
+ return htmdate
+def mode_edit():
+ editnum=exect.replace("edit:","")
+ htmdate= readHtmlEdit()
+ iddata=edit_date(editnum)
+ htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
+ htmdate=htmdate.replace("<!--ch-value//-->",iddata['chtxt'])
+ htmdate=htmdate.replace("<!--btime-value//-->",iddata['btime'])
+ htmdate=htmdate.replace("<!--etime-value//-->",iddata['etime'])
+ htmdate=htmdate.replace("<!--type-value//-->",iddata['type'])
+ htmdate=htmdate.replace("<!--ch-value//-->",iddata['chtxt'])
+ htmdate=htmdate.replace("<!--title-value//-->",iddata['title'])
+ htmdate=htmdate.replace("<!--size-value//-->",size)
+ htmdate=htmdate.replace("<!--opts-value//-->",iddata["opt"])
+ htmdate=htmdate.replace("<!--exec-value//-->","edit-exec:"+editnum)
+ return htmdate
dbpath=path+"ch.db"
database=getdb()
-f=cgi.FieldStorage()
-
btime=""
etime=""
title=""
chtxt=""
type="res"
bt=""
+station_name=""
+mode=""
getRecDate()
if f.getfirst('mode')=="schedule":
getRecDate()
-
###ここからiEPG用の読み出し
if f.getfirst('station_name'):
station=f.getfirst('station_name')
- chtxt=station_name2chtxt(station)
+ chtxt=station2chtxt(station)
+ if chtxt=="n\/a":
+ mode="iepg-add"
+ station_name=station
+ exect="iepg-add"
if f.getfirst('station'):
station=f.getfirst('station')
chtxt=station2chtxt(station)
+ if chtxt=="n\/a":
+ mode="iepg-add"
+ station_name=station
+ exect="iepg-add"
###ここから外部からの読み出しの場合
if f.getfirst('type'):
type=f.getfirst('type')
chtxt=f.getfirst('chtxt')
if f.getfirst('btime'):
btime=f.getfirst('btime')
- #bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
bt=datetime.datetime(*time.strptime(btime,"%Y-%m-%d %H:%M:%S")[:-3])
if f.getfirst('etime'):
etime=f.getfirst('etime')
- #et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
et=datetime.datetime(*time.strptime(etime,"%Y-%m-%d %H:%M:%S")[:-3])
if bt !="":
delt=et-bt
exect=""
if f.getfirst('exec',""):
exect=f.getfirst('exec',"")
+if exect=="schedule":
+ mode="schedule"
+elif re.search('edit:',exect):
+ mode="edit"
+elif exect=="iepg-add":
+ mode="iepg-add"
+elif exect=="iepg-show":
+ mode="iepg-show"
+elif exect=="iepg-add_yes"
+ mode="iepg-add-yes"
htmdate= readHtmlSrcSimple()
htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
htmdate=htmdate.replace("<!--btime-value//-->",btime)
elif restxt=="over":
htmdate=readRecFinisOver()
exect=""
-#
if (chtxt != "")and(title != "")and(btime!="")and(etime!="")and(opts!="")and(re.search('edit-exec:',exect)):
editnum=exect.replace("edit-exec:","")
#restxt=change_reserv(id, type, keyword, chtxt, btime, etime, deltatime, opt, deltaday)
elif restxt=="over":
htmdate=readRecFinisOver()
exect=""
-if exect=="schedule":
- htmdate=readRecSchedule()
-if re.search('edit:',exect):
- editnum=exect.replace("edit:","")
- htmdate= readHtmlEdit()
- iddata=edit_date(editnum)
- htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
- htmdate=htmdate.replace("<!--ch-value//-->",iddata['chtxt'])
- htmdate=htmdate.replace("<!--btime-value//-->",iddata['btime'])
- htmdate=htmdate.replace("<!--etime-value//-->",iddata['etime'])
- htmdate=htmdate.replace("<!--type-value//-->",iddata['type'])
- htmdate=htmdate.replace("<!--ch-value//-->",iddata['chtxt'])
- htmdate=htmdate.replace("<!--title-value//-->",iddata['title'])
- htmdate=htmdate.replace("<!--size-value//-->",size)
- htmdate=htmdate.replace("<!--opts-value//-->",iddata["opt"])
- htmdate=htmdate.replace("<!--exec-value//-->","edit-exec:"+editnum)
+if mode=="schedule":
+ htmdate=mode_normal()
+elif mode=="edit":
+ htmdate=mode_edit()
+elif mode=="iepg-add":
+ htmdate=mode_iepg_add(f.getfirst('iepg_station'))
+elif mode=="iepg-add-yes":
+ if f.getfirst('iepg_station') and f.getfirst('iepg_chtxt'):
+ database.add_iepg(f.getfirst('iepg_station'),f.getfirst('iepg_chtxt'))
+ htmdate=mode_iepg_fin()
+elif mode=="iepg-show":
+ htmdate=mode_iepg_show()
print "Content-Type: text/html\n"
print htmdate
+