# -*- coding:utf-8 -*-
from os import chdir
html = """
LU
%s
"""
noms = 'dou² smokadezign vachy malacath margeta lord_kellmar tetlis kitni zell'.split()
durees = [0, 2, 4, 8, 16]
def results():
"show results"
f = open('stats.txt', 'r')
stathtml = '\n'
c = 'o'
while True:
l = f.readline().strip().split()
if not l:
break
l[1] = int(l[1])
stats = [l[0], ''+(c*l[1])+''+(c*(durees[-1]-l[1])), l[1]]
stathtml += "| %s | %s | %s |
\n" % (stats[0], stats[1], stats[2])
stathtml += '
'
f.close()
return stathtml
def index(req):
chdir('/home/www/py/randpoll')
req.content_type = 'text/html'
terrorists = req.form.items()
# on check si il envoit ses rep ou si il demande les choix
try:
z = terrorists[0][0]
z = 1
except:
z = 0
if z:
try:
# on met les anciennes stats dans olstats[] (si y'en a)
stats = open('stats.txt', 'r')
olstats = []
while True:
l = stats.readline().strip()
if not l:
break
olstats.append(l.split())
olstats[-1][1] = int(olstats[-1][1])
stats.close()
# si le fichier existe pas ..
except:
olstats = []
# convertit les reponses en int
nestats = []
for i in range(len(terrorists)):
nestats.append([terrorists[i][0], int(terrorists[i][1])])
# merge/fait la moyenne entre les news et les old
stats = []
for t in nestats:
ok = 0
for e in olstats:
if e[0] == t[0]:
stats.append([e[0], (e[1]+t[1])/2])
ok = 1
break
if not ok: # si c'est la 1ere fois qu'on le voit
stats.append(t)
# pour ceux qui étaient la avant mais plus now
for e in olstats:
if not e[0] in str(stats):
stats.append(e)
# on les récrit
f = open('stats.txt', 'w')
for s in stats:
f.write('%s %s\n' % (s[0], s[1]))
f.close()
return html % results()
# si le visiteur arrive tout juste
else:
form = '