summaryrefslogtreecommitdiff
path: root/cgi-bin/index.py
blob: 189c0f6ddbb397ea0a5edc4554e5690dfa01f3f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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>")