diff options
Diffstat (limited to 'cgi-bin/index.py')
-rwxr-xr-x | cgi-bin/index.py | 118 |
1 files changed, 18 insertions, 100 deletions
diff --git a/cgi-bin/index.py b/cgi-bin/index.py index 189c0f6..20480a4 100755 --- a/cgi-bin/index.py +++ b/cgi-bin/index.py @@ -1,83 +1,16 @@ #!/usr/bin/python # -*- coding: utf8 -*- -import cgi, cgitb, os.path, datetime, re +import cgi, cgitb, re, display, config +print ("Content-Type: text/html") +print ("") +# Enable CGI debugging cgitb.enable() -root="img/" -src_root="../img/" - -class Link: - def __init__(self, filename=""): - if not filename or filename == "latest": - self.img=os.path.split(os.path.realpath(root+"latest.jpeg"))[1] - else: - self.img=filename+".jpeg" - - def image(self, target): - if self.detect(src_root+target): - src=os.path.split(target) - return os.path.relpath(src_root + src[1]) - else: - return os.path.relpath(src_root + "notfound.jpeg") - - def href(self, target): - #print os.path.realpath(root+target) - if target == self.img: - target = os.path.split(target)[1] - return target[:12] - else: - return "?f=" + target[:12] - - def detect(self, filename): - if os.path.exists(os.path.realpath(root+filename)): - #print os.path.realpath(filename) - return True - else: - #print os.path.realpath(filename) - return False - - def link(self, target, link): - #print target - if self.detect(target): - return "<a href=\""+self.href(target)+"\">"+link+"</a>" - else: - return "<span>"+link+"</span>" - - def delta(self, delta): - date=os.path.split(self.img) - date=os.path.splitext(date[1]) - date=date[0] - curdate=datetime.datetime.strptime(date, "%Y%m%d%H%M") - pm = delta[:0] - if delta.endswith('m'): - num = 10 - else: - num = 1 - if delta.startswith('-'): - num = num * -1 - if delta.endswith('w'): - targetdate=curdate-datetime.timedelta(weeks=num) - if delta.endswith('d'): - targetdate=curdate-datetime.timedelta(days=num) - if delta.endswith('h'): - targetdate=curdate-datetime.timedelta(hours=num) - if delta.endswith('m'): - targetdate=curdate-datetime.timedelta(minutes=num) - return datetime.datetime.strftime(targetdate, "%Y%m%d%H%M")+".jpeg" - -form = cgi.FieldStorage() - -param=form.getvalue("f") - -if re.match("^[a-zA-Z0-9]*$", str(param)): - img = Link(param) -else: - img = Link("latest") +query = cgi.FieldStorage() +param = query.getvalue("f") -print ("Content-Type: text/html") -print ("") print ("<!DOCTYPE html>") print ("<html>") print ("<head>") @@ -86,30 +19,15 @@ print ("<title>Hnízdo</title>") print ("<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/style.css\">") print ("</head>") print ("<body>") -#print (img.img) -print ("<header>") -print ("<h1>Hnízdo</h1>") -print ("<nav>") -print (img.link(img.delta('+w'), '-týden')) -print (img.link(img.delta('+d'), '-den')) -print (img.link(img.delta('+h'), '-hodina')) -print (img.link(img.delta('+m'), 'minulý')) -print ("<a href=\"?f=latest\">nejnovější</a>") -print (img.link(img.delta('-m'), 'následující')) -print (img.link(img.delta('-h'), '+hodina')) -print (img.link(img.delta('-d'), '+den')) -print (img.link(img.delta('-w'), '+týden')) -print ("</nav>") -print ("</header>") -print ("<article id=\"prev\">") -print ("<a href=\"" + img.href(img.delta('+m')) + "\"><img class=\"prev\" src=\"" + img.image(img.delta('-m')) + "\" alt=\"\" title=\"\" /></a>") -print ("</article>") -print ("<article id=\"now\">") -print ("<img class=\"now\" src=\"" + img.image(img.img) + "\" alt=\"\" title=\"\" />") -print ("</article>") -print ("<article id=\"next\">") -print ("<a href=\"" + img.href(img.delta('-m')) + "\"><img class=\"next\" src=\"" + img.image(img.delta('+m')) + "\" alt=\"\" title=\"\" /></a>") -print ("</article>") -print ("<footer>") -print ("<a href=\"../all.html\" title=\"všechny fotky\">vše</a>") -print ("</footer></body></html>") + +if param in config.special: + body=display.Body(param) +elif re.match("^20[0-9]{2}(0[0-9]|1[1-2])([0-2][0-9]|3[0-1])(0[0-9]|1[0-9]|2[0-3])([0-5][0-9])$", str(param)): + body=display.Body(param) +else: + body=display.Body("latest") + +body.page() + +print("</body>") +print("</html>") |