OSDN Git Service

some fix
[rec10/rec10-git.git] / Rec10WEB / trunk / src / rec10web.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import cgi
6 import cgitb
7 import sqlite3
8 import os
9 import datetime
10 cgitb.enable()
11 path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
12 dbpath=path+"ch.db"
13
14
15 def getchtxt():
16     db=sqlite3.connect(dbpath)
17     chopt=""
18     for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata"):
19         chdisplay=""
20         for bctype,channel,display in db.execute("SELECT bctype,channel,display FROM ch WHERE channel=\""+ontv+"\""):
21             chdisplay=display
22         chopt=chopt+"<option  value="+chtxt+">"+display+"</option>\n                "
23     db.close()
24     return chopt
25 def reserv(type,keyword,chtxt,btime,etime,deltatime,opt,deltaday):
26     db=sqlite3.connect(dbpath)
27     recline="\""+type+"\",\""+chtxt+"\",\""+keyword+"\",datetime(\""+btime+"\"),datetime(\""+etime+"\"),\""+deltatime+"\",\""+opt+"\",\""+deltaday+"\""
28     #print recline
29     db.execute('insert into rectime ("type","chtxt","title","btime","etime","deltatime","opt","deltaday") values ('+recline+')')
30     db.commit()
31     db.close()
32 def station2chtxt(station):
33     db=sqlite3.connect(dbpath)
34     ret=""
35     for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE station=\""+station+"\""):
36         ret=chtxt
37     db.close()
38     return ret
39 def readHtmlSrcSimple():
40     f = open(path+'rswi.htm')
41     ret=f.read()
42     f.close()
43     return ret
44 def readRecFinisSimple():
45     f = open(path+'fin.htm')
46     ret=f.read()
47     f.close()
48     return ret
49 f=cgi.FieldStorage()
50
51 btime=""
52 etime=""
53 title=""
54 chtxt=""
55 type="res"
56 bt=""
57 ###ここからiEPG用の読み出し
58 if f.getfirst('station'):
59     station=f.getfirst('station')
60     chtxt=station2chtxt(station)
61 ###ここから外部からの読み出しの場合
62 if f.getfirst('type'):
63     type=f.getfirst('type')
64 if f.getfirst('title'):
65     title=f.getfirst('title')
66 if f.getfirst('chtxt'):
67     chtxt=f.getfirst('chtxt')
68 if f.getfirst('btime'):
69     btime=f.getfirst('btime')
70     bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
71 if f.getfirst('etime'):
72     etime=f.getfirst('etime')
73     et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
74     if bt !="":
75         delt=et-bt
76         dt=delt.days*24*60+delt.seconds
77         if dt<0:
78             dd=datetime.timedelta(days=1)
79             et=et+dd
80             etime=et.strftime("%Y-%m-%d %H:%M:%S")
81         if dt<-1*24*60+1:
82             d1=datetime.datetime(bt.year,0,0)
83             d2=datetime.datetime(bt.year+1,0,0)
84             dd=d2-d1
85             et=et+dd
86             etime=et.strftime("%Y-%m-%d %H:%M:%S")
87         
88 size=""
89 if f.getfirst('size'):
90     size=f.getfirst('size')
91 opts=""
92 if f.getfirst('opts'):
93     opts=f.getfirst('opts')
94 deltahour=""
95 if f.getfirst('deltahour',""):
96     deltahour=f.getfirst('deltahour',"")
97 deltaday=""
98 if f.getfirst('deltaday',""):
99     deltaday=f.getfirst('deltaday',"")
100 exect=""
101 if f.getfirst('exec',""):
102     exect=f.getfirst('exec',"")
103     
104 htmdate= readHtmlSrcSimple()
105 htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
106
107 htmdate=htmdate.replace("<!--btime-value//-->",btime)
108 htmdate=htmdate.replace("<!--etime-value//-->",etime)
109 htmdate=htmdate.replace("<!--type-value//-->",type)
110 htmdate=htmdate.replace("<!--ch-value//-->",chtxt)
111 htmdate=htmdate.replace("<!--title-value//-->",title)
112 htmdate=htmdate.replace("<!--size-value//-->",size)
113 htmdate=htmdate.replace("<!--opts-value//-->",opts)
114
115 if (chtxt != "")and(title != "")and(btime!="")and(etime!="")and(opts!="")and(exect=="yes"):
116     reserv(type, title, chtxt, btime, etime, deltahour, opts, deltaday)
117     htmdate=readRecFinisSimple()
118     exect=""
119 #
120 print htmdate
121
122