OSDN Git Service

enable to show schedule is busy
[rec10/rec10-git.git] / Rec10WEB / trunk / src / rec10web.py
index c15b0b3..bcfd0fe 100644 (file)
@@ -6,11 +6,11 @@ import cgi
 import cgitb
 import sqlite3
 import os
+import datetime
 cgitb.enable()
 path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
 dbpath=path+"ch.db"
 
-
 def getchtxt():
     db=sqlite3.connect(dbpath)
     chopt=""
@@ -22,12 +22,41 @@ def getchtxt():
     db.close()
     return chopt
 def reserv(type,keyword,chtxt,btime,etime,deltatime,opt,deltaday):
+    MaxT=2
+    MaxS=2
     db=sqlite3.connect(dbpath)
-    recline="\""+type+"\",\""+chtxt+"\",\""+keyword+"\",datetime(\""+btime+"\"),datetime(\""+etime+"\"),\""+deltatime+"\",\""+opt+"\",\""+deltaday+"\""
-    print recline
-    db.execute('insert into rectime ("type","chtxt","title","btime","etime","deltatime","opt","deltaday") values ('+recline+')')
-    db.commit()
+    bt="\'"+btime+"\'"
+    et="\'"+etime+"\'"
+    dbexe="SELECT chdata.bctype,rectime.chtxt,rectime.title FROM rectime INNER JOIN chdata ON rectime.chtxt=chdata.chtxt"
+    #dbexe="SELECT bctype,chtxt,title FROM rectime INNER JOIN chdata ON rectime.chtxt=chdata.chtxt"
+
+    dbexe=dbexe+" WHERE NOT( ( rectime.etime <= "+bt+" ) OR ( rectime.btime >= "+et+" ) )"
+    for bctypet, chtxtt, titlet in db.execute(dbexe):
+        if bctypet.find("cs")>-1:
+            MaxS=MaxS-1
+        elif bctypet.find("bs")>-1:
+            MaxS=MaxS-1
+        elif bctypet.find("te")>-1:
+            MaxT=MaxT-1
+    bctype=""
+    rett=""
+    for bctypet, chtxtt in db.execute("SELECT bctype,chtxt FROM chdata WHERE chtxt=\'"+chtxt+"\'"):
+        bctype=bctypet
+    if bctype.find("cs")>-1:
+        MaxS=MaxS-1
+    elif bctype.find("bs")>-1:
+        MaxS=MaxS-1
+    elif bctype.find("te")>-1:
+        MaxT=MaxT-1
+    if MaxS>-1 and MaxT>-1:
+        recline="\""+type+"\",\""+chtxt+"\",\""+keyword+"\",datetime(\""+btime+"\"),datetime(\""+etime+"\"),\""+deltatime+"\",\""+opt+"\",\""+deltaday+"\""
+        #print recline
+        db.execute('insert into rectime ("type","chtxt","title","btime","etime","deltatime","opt","deltaday") values ('+recline+')')
+        db.commit()
+    else:
+        rett="over"
     db.close()
+    return rett
 def station2chtxt(station):
     db=sqlite3.connect(dbpath)
     ret=""
@@ -40,11 +69,17 @@ def readHtmlSrcSimple():
     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
 f=cgi.FieldStorage()
 
 btime=""
@@ -52,6 +87,7 @@ etime=""
 title=""
 chtxt=""
 type="res"
+bt=""
 ###ここからiEPG用の読み出し
 if f.getfirst('station'):
     station=f.getfirst('station')
@@ -65,8 +101,24 @@ if f.getfirst('chtxt'):
     chtxt=f.getfirst('chtxt')
 if f.getfirst('btime'):
     btime=f.getfirst('btime')
+    bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
 if f.getfirst('etime'):
     etime=f.getfirst('etime')
+    et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
+    if bt !="":
+        delt=et-bt
+        dt=delt.days*24*60*60+delt.seconds
+        if dt<0:
+            dd=datetime.timedelta(days=1)
+            et=et+dd
+            etime=et.strftime("%Y-%m-%d %H:%M:%S")
+        if dt<-1*24*60*60:
+            d1=datetime.datetime(bt.year,0,0)
+            d2=datetime.datetime(bt.year+1,0,0)
+            dd=d2-d1
+            et=et+dd
+            etime=et.strftime("%Y-%m-%d %H:%M:%S")
+        
 size=""
 if f.getfirst('size'):
     size=f.getfirst('size')
@@ -95,10 +147,12 @@ htmdate=htmdate.replace("<!--size-value//-->",size)
 htmdate=htmdate.replace("<!--opts-value//-->",opts)
 
 if (chtxt != "")and(title != "")and(btime!="")and(etime!="")and(opts!="")and(exect=="yes"):
-    reserv(type, title, chtxt, btime, etime, deltahour, opts, deltaday)
-    htmdate=readRecFinisSimple()
+    restxt=reserv(type, title, chtxt, btime, etime, deltahour, opts, deltaday)
+    if restxt=="":
+        htmdate=readRecFinisSimple()
+    elif restxt=="over":
+        htmdate=readRecFinisOver()
     exect=""
 #
 print htmdate
 
-