diff options
author | Ctibor <ctibor@brancik.cz> | 2017-03-22 20:01:27 +0100 |
---|---|---|
committer | Ctibor <ctibor@brancik.cz> | 2017-03-22 20:01:27 +0100 |
commit | 93b96ca1685a22c3fa3aca2f6f2a1307438740d0 (patch) | |
tree | 398636187c39d9ddf17c38ad5a3c754ee3516db3 /cgi-bin | |
download | hnizdo-93b96ca1685a22c3fa3aca2f6f2a1307438740d0.tar.gz hnizdo-93b96ca1685a22c3fa3aca2f6f2a1307438740d0.tar.bz2 |
"Initial commit"
Diffstat (limited to 'cgi-bin')
-rwxr-xr-x | cgi-bin/index.py | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/cgi-bin/index.py b/cgi-bin/index.py new file mode 100755 index 0000000..189c0f6 --- /dev/null +++ b/cgi-bin/index.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- + +import cgi, cgitb, os.path, datetime, re + +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") + +print ("Content-Type: text/html") +print ("") +print ("<!DOCTYPE html>") +print ("<html>") +print ("<head>") +print ("<meta charset=\"UTF-8\">") +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>") |