OSDN Git Service

Import rec10web
[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 cgitb.enable()
10 path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
11 dbpath=path+"ch.db"
12
13
14 def getchtxt():
15     db=sqlite3.connect(dbpath)
16     chopt=""
17     for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata"):
18         chdisplay=""
19         for bctype,channel,display in db.execute("SELECT bctype,channel,display FROM ch WHERE channel=\""+ontv+"\""):
20             chdisplay=display
21         chopt=chopt+"<option  value="+chtxt+">"+display+"</option>\n                "
22     db.close()
23     return chopt
24 def reserv(type,keyword,chtxt,btime,etime,deltatime,opt,deltaday):
25     db=sqlite3.connect(dbpath)
26     recline="\""+type+"\",\""+chtxt+"\",\""+keyword+"\",datetime(\""+btime+"\"),datetime(\""+etime+"\"),\""+deltatime+"\",\""+opt+"\",\""+deltaday+"\""
27     print recline
28     db.execute('insert into rectime ("type","chtxt","title","btime","etime","deltatime","opt","deltaday") values ('+recline+')')
29     db.commit()
30     db.close()
31 def station2chtxt(station):
32     db=sqlite3.connect(dbpath)
33     ret=""
34     for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE station=\""+station+"\""):
35         ret=chtxt
36     db.close()
37     return ret
38 def readHtmlSrcSimple():
39     f = open(path+'rswi.htm')
40     ret=f.read()
41     f.close()
42     return ret
43 def readRecFinisSimple():
44     f = open(path+'fin.htm')
45     ret=f.read()
46     f.close()
47     return ret
48 f=cgi.FieldStorage()
49
50 btime=""
51 etime=""
52 title=""
53 chtxt=""
54 type="res"
55 ###ここからiEPG用の読み出し
56 if f.getfirst('station'):
57     station=f.getfirst('station')
58     chtxt=station2chtxt(station)
59 ###ここから外部からの読み出しの場合
60 if f.getfirst('type'):
61     type=f.getfirst('type')
62 if f.getfirst('title'):
63     title=f.getfirst('title')
64 if f.getfirst('chtxt'):
65     chtxt=f.getfirst('chtxt')
66 if f.getfirst('btime'):
67     btime=f.getfirst('btime')
68 if f.getfirst('etime'):
69     etime=f.getfirst('etime')
70 size=""
71 if f.getfirst('size'):
72     size=f.getfirst('size')
73 opts=""
74 if f.getfirst('opts'):
75     opts=f.getfirst('opts')
76 deltahour=""
77 if f.getfirst('deltahour',""):
78     deltahour=f.getfirst('deltahour',"")
79 deltaday=""
80 if f.getfirst('deltaday',""):
81     deltaday=f.getfirst('deltaday',"")
82 exect=""
83 if f.getfirst('exec',""):
84     exect=f.getfirst('exec',"")
85     
86 htmdate= readHtmlSrcSimple()
87 htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
88
89 htmdate=htmdate.replace("<!--btime-value//-->",btime)
90 htmdate=htmdate.replace("<!--etime-value//-->",etime)
91 htmdate=htmdate.replace("<!--type-value//-->",type)
92 htmdate=htmdate.replace("<!--ch-value//-->",chtxt)
93 htmdate=htmdate.replace("<!--title-value//-->",title)
94 htmdate=htmdate.replace("<!--size-value//-->",size)
95 htmdate=htmdate.replace("<!--opts-value//-->",opts)
96
97 if (chtxt != "")and(title != "")and(btime!="")and(etime!="")and(opts!="")and(exect=="yes"):
98     reserv(type, title, chtxt, btime, etime, deltahour, opts, deltaday)
99     htmdate=readRecFinisSimple()
100     exect=""
101 #
102 print htmdate
103
104