OSDN Git Service

simplify many codes.
[rec10/rec10-git.git] / Rec10WEB / trunk / src / rec10web.py
index 1edceeb..faf4101 100644 (file)
@@ -84,6 +84,17 @@ def getRecDate():
     f=open(path+"/recdatum.csv","w")
     f.write(recdata)
     f.close()
+def getiEPGDate():
+    dl=database.select_all_iepg()
+    recdata="id,name,chtxt\n"
+    #print dl
+    s=""
+    for d in dl:
+        s=s+d[0]+","+d[1]+","+d[2]+"\n"
+    recdata=recdata+s
+    f=open(path+"/iepgdatum.csv","w")
+    f.write(recdata)
+    f.close()
 def getchtxt():
     dl=database.select_all_chdata()
     chopt=""
@@ -211,7 +222,11 @@ def change_reserv(id,type,keyword,chtxt,btime,etime,deltatime,opt,deltaday):
     return rett
 def station2chtxt(station):
     ret=""
-    sta=database.select_by_station_iepg(station):
+    #try:
+    database.new_iepg()
+    #except:
+    #    ""
+    sta=database.select_by_station_iepg(station)
     if len(sta)>0:
         ret=sta[0][1]
     else:
@@ -222,22 +237,11 @@ def readHtmlSrcSimple():
     ret=f.read()
     f.close()
     return ret
-def readHtmlEdit():
-    f = open(path+'rswi_edit.htm')
-    ret=f.read()
-    f.close()
-    return ret
-
 def readRecFinisSimple():
     f = open(path+'fin.htm')
     ret=f.read()
     f.close()
     return ret
-def readRecFinisOver():
-    f = open(path+'finover.htm')
-    ret=f.read()
-    f.close()
-    return ret
 def readRecSchedule():
     f = open(path+'schedule.htm')
     ret=f.read()
@@ -248,16 +252,16 @@ def readiEPGadd():
     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 get_fin(string,refreshurl):
+    htmdate=readRecFinisSimple()
+    htmdate=htmdate.replace('<!--text_for_replace_fin//-->',string)
+    htmdate=htmdate.replace('<!--url_for_replace_fin//-->',refreshurl)
+    return htmdate
 def mode_iepg_add(station):
     htmdate=readiEPGadd()
     htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
@@ -265,21 +269,37 @@ def mode_iepg_add(station):
     htmdate=htmdate.replace("<!--iepg_title-value//-->",station)
     return htmdate
 def mode_iepg_fin():
-    htmdate=readiEPGfin()
-    return htmdate
+    s="epgデータの追加を完了しました。<br>\n録画を行う場合はもう一度おねがいします。<br>"
+    u="rec10web.py?exec=iepg-show"
+    return get_fin(s,u)
 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_iepg_del():
+    s="epgデータを削除しました。"
+    u="rec10web.py?exec=iepg-show"
+    return get_fin(s,u)
+def mode_iepg_del_miss():
+    s="epgデータの削除に失敗しました。"
+    u="rec10web.py?exec=iepg-show"
+    return get_fin(s,u)
 def mode_schedule():
     htmdate=readRecSchedule()
     return htmdate
+def mode_recfin():
+    s="予約が終了しました。移動します。"
+    u="rec10web.py?exec=schedule"
+    return get_fin(s,u)
+def mode_recover():
+    s="最大予約可能数を超えています"
+    u="rec10web.py?exec=schedule"
+    return get_fin(s,u)
+def mode_normal():
+    htmdate=readHtmlSrcSimple()
+    htmdate=htmdate.replace("<!--exec-value//-->","yes")
 def mode_edit():
     editnum=exect.replace("edit:","")
-    htmdate= readHtmlEdit()
+    htmdate= readHtmlSrcSimple()
     iddata=edit_date(editnum)
     htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
     htmdate=htmdate.replace("<!--ch-value//-->",iddata['chtxt'])
@@ -302,9 +322,6 @@ type="res"
 bt=""
 station_name=""
 mode=""
-getRecDate()
-if f.getfirst('mode')=="schedule":
-    getRecDate()
 ###ここからiEPG用の読み出し
 if f.getfirst('station_name'):
     station=f.getfirst('station_name')
@@ -363,15 +380,18 @@ if f.getfirst('exec',""):
     exect=f.getfirst('exec',"")
 if exect=="schedule":
     mode="schedule"
+    getRecDate()
 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"
+elif exect=="iepg-add_yes":
     mode="iepg-add-yes"
-htmdate= readHtmlSrcSimple()
+elif exect=="iepg-del":
+    mode="iepg-del"
+htmdate= mode_normal()
 htmdate=htmdate.replace("<!--text_for_replace_chtxt_input//-->",getchtxt())
 htmdate=htmdate.replace("<!--btime-value//-->",btime)
 htmdate=htmdate.replace("<!--etime-value//-->",etime)
@@ -405,40 +425,55 @@ if f.getfirst('type')=="keyday":
     if dayt:
         rett=rett+reserv_recday(title, chtxt, btime, etime, deltahour, opts, deltaday, dayt)
     if rett=="":
-        htmdate=readRecFinisSimple()
+        htmdate=mode_recfin()
     else:
-        htmdate=readRecFinisOver()
+        htmdate=mode_recover()
     chtxt=""
     exect=""
 if (chtxt != "")and(title != "")and(btime!="")and(etime!="")and(opts!="")and(exect=="yes"):
     restxt=reserv(type, title, chtxt, btime, etime, deltahour, opts, deltaday)
     if restxt=="":
-        htmdate=readRecFinisSimple()
+        htmdate=mode_recfin()
     elif restxt=="over":
-        htmdate=readRecFinisOver()
+        htmdate=mode_recover()
     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)
     restxt=change_reserv(editnum,type, title, chtxt, btime, etime, deltahour, opts, deltaday)
     if restxt=="":
-        htmdate=readRecFinisSimple()
+        htmdate=mode_recfin()
     elif restxt=="over":
-        htmdate=readRecFinisOver()
+        htmdate=mode_recover()
     exect=""
 if mode=="schedule":
     htmdate=mode_normal()
 elif mode=="edit":
     htmdate=mode_edit()
 elif mode=="iepg-add":
-    htmdate=mode_iepg_add(f.getfirst('iepg_station'))
+    htmdate=mode_iepg_add(station_name)
 elif mode=="iepg-add-yes":
+    try:
+        database.new_iepg()
+    except:
+        ""
     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":
+    getiEPGDate()
     htmdate=mode_iepg_show()
-print "Content-Type: text/html\n"
+elif mode=="iepg-del":
+    s=f.getfirst('iepgdelnum')
+    htmdate=""
+    try:
+        for st in s.split(","):
+            if st!="":
+                database.del_by_id_iepg(st)
+        htmdate=mode_iepg_del()
+    except:
+        htmdate=mode_iepg_del_miss()
+print "Content-Type: text/html"
 print htmdate
-
+#print exect
+#print mode