-
Notifications
You must be signed in to change notification settings - Fork 0
/
gifgift.py
executable file
·155 lines (118 loc) · 5.77 KB
/
gifgift.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python
import tornado.ioloop
import tornado.web
import os
import sys
import datetime
import json
import socket
#date_object = datetime.strptime('2013-12-30 17:00', '%Y-%M-%D')
sys.path.append('.')
port = 1984
analytics = False
if not "MacBook" in socket.gethostname() :
analytics = True
print "using analytics"
debug = False
else:
print "not using analytics"
debug = True
class UpdateCookieHandler(tornado.web.RequestHandler):
def get(self, day, state):
if debug: print day, ':', state
cookieData = self.get_cookie("caravel_calendar", default=None)
cookie = None
if cookieData:
cookie = json.loads(cookieData)
for i in range(1, 26):
if not str(i) in cookie.keys():
cookie = None
break
if not cookie:
print 'new Cookie'
cookie = {}
for i in range (1, 26):
cookie[i] = False
self.set_cookie("caravel_calendar", json.dumps(cookie, separators=(',', ':')), path='/', expires_days=300)
if state == 'yes':
cookie[day] = True
else:
cookie[day] = False
self.set_cookie("caravel_calendar", json.dumps(cookie, separators=(',', ':')), path='/', expires_days=300)
self.write('Ok')
class MainHandler(tornado.web.RequestHandler):
def get(self):
previews = []
days = [ # ['gifName', 'YYYY-MM-DD HH:MM' Starting point hour', 'author', active, date, state]
['GIF1.gif','2013-12-10 00:00', 'joseph', False, 10, False],
['Geoffroi_04.gif','2013-12-15 00:00', 'joseph', False, 15, False],
['Geoffroi_03.gif','2013-12-24 00:00', 'maxime', False, 24, False],
['3_max_trap.gif','2013-12-03 00:00', 'geoffroi', False,3, False],
['gif-playa150x108.gif','2013-12-22 00:00', 'maxime', False, 22, False],
['Xmas_tree_watercolor.gif','2013-12-14 00:00', 'peter', False, 14, False],
['night.gif','2013-12-04 00:00', 'gaelle', False, 4, False],
['6_max_camap.gif','2013-12-06 00:00', 'marie', False, 6, False],
['Geoffroi_01.gif','2013-12-01 00:00', 'joseph', False, 1, False],
['gif-cadeau150x108.gif','2013-12-20 00:00', 'joseph', False, 20, False],
['GIF4.gif','2013-12-08 00:00', 'joseph', False, 8, False],
['GIF_iran_002.gif','2013-12-23 00:00', 'joseph', False, 23, False],
['gif-festin-anim-B-150x108.gif','2013-12-21 21:00', 'joseph', False, 21, False],
['9_max_tapis.gif','2013-12-02 00:00', 'joseph', False, 2, False],
['Xmas_triangle.gif','2013-12-12 00:00', 'joseph', False, 12, False],
['GIF3.gif','2013-12-17 00:00', 'joseph', False, 17, False],
['GIF_france.gif','2013-12-13 00:00', 'joseph', False, 13, False],
['gif_foot-prints-snow-blue-reparation150x108.gif','2013-12-07 00:00', 'joseph', False, 7, False],
['Geoffroi_02.gif','2013-12-16 00:00', 'joseph', False, 16, False],
['GIF2.gif','2013-12-18 00:00', 'joseph', False, 18, False],
['23_max_sapin.gif','2013-12-09 00:00', 'joseph', False, 9, False],
['GIF_nigeria_002.gif','2013-12-05 00:00', 'joseph', False, 5, False],
['present.gif','2013-12-19 10:00', 'joseph', False, 19, False],
['GIF_groenland.gif','2013-12-11 00:00', 'joseph', False, 11, False],
['gifgift25th_v002.gif','2013-12-25 00:00', 'joseph', False, 25, False],
]
now = datetime.datetime.now()
cookieData = self.get_cookie("caravel_calendar", default=None)
cookie = None
if cookieData:
cookie = json.loads(cookieData)
for i in range(1, 26):
if not str(i) in cookie.keys():
cookie = None
break
if not cookie:
print 'new Cookie'
cookie = {}
for i in range (1, 26):
cookie[i] = False
self.set_cookie("caravel_calendar", json.dumps(cookie, separators=(',', ':')), path='/', expires_days=300)
else:
for i in range (0, len(days)):
days[i][5] = cookie[str(days[i][4])]
for i in range (0,len(days)):
if datetime.datetime.strptime(days[i][1], '%Y-%m-%d %H:%M') <= now:
days[i][3] = True
if None:
days[i][3] = True
past25 = True if datetime.datetime.strptime("2013-12-25 00:00", '%Y-%m-%d %H:%M') <= now else False
self.render('gifgift.html', days=days, analytics=analytics, past25=past25)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", MainHandler),
(r"/setCookie/(.*)/(.*)", UpdateCookieHandler),
]
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
)
tornado.web.Application.__init__(self, handlers, debug=debug, **settings)
if __name__ == "__main__":
print "\nStarting ", __file__
print "serveur demarre sur port ", port
if debug:
print "Debug Mode ON"
import datetime
print datetime.datetime.now()
app = Application()
app.listen(port)
tornado.ioloop.IOLoop.instance().start()