-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
92 lines (79 loc) · 3.3 KB
/
Copy pathindex.py
File metadata and controls
92 lines (79 loc) · 3.3 KB
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
# -*- coding: utf-8 -*-
from bottle import *
from hashtagman import *
from hpics import *
version = "#HashtagMan v0.1.0a2"
@route('/')
def index() -> "string":
if not request.cookies.tip:
sol = li[randint(0, len(li)-1)]
response.set_cookie("sol", sol)
## -1 what you actually want
response.set_cookie("maxf", "8")
response.set_cookie("curf", "0")
response.set_cookie("tip", "")
return version +": "+ \
greeting()+"<br>"+\
"<form action=\"/\" method=\"POST\">"+\
"<input type=\"text\" name=\"ntip\" maxlength=\"1\">"+\
"<input type=\"submit\" name=\"guess\" value=\"raten\"> <br />" +\
pics[0]
else:
tip = request.cookies.tip
sol = request.cookies.sol
curf = request.cookies.curf
maxf = request.cookies.maxf
return "Welcome back!<br>"+\
"<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>" +\
'<span style="font-family:\'Source Code Pro\'">' + partSol(tip, sol) + '</span>' + "<br />" +\
"Faults " + curf + " / " + str(int(maxf)+1) + ": " + falseChars(tip, sol) +\
"<form action=\"/\" method=\"POST\">"+\
"<input type=\"text\" name=\"ntip\" maxlength=\"1\">"+\
"<input type=\"submit\" name=\"guess\" value=\"raten\"> <br />" +\
pics[int(curf)]
@route('/', method='POST')
def do_index() -> "string":
ntip = request.forms.get("ntip")
ttip = request.cookies.tip
if not ntip:
return """
<p>Please insert a letter. <br />
<a href="http://localhost:8080">go back -></a>
</p>
"""
ntip = ntip.upper()
if ntip.upper() in ttip:
return """
<p>Please do not insert the same letter. <br />
<a href="http://localhost:8080">go back -></a>
</p>
"""
else:
tip = ttip + ntip
response.set_cookie("tip", tip)
sol = request.cookies.sol
curf = request.cookies.curf
maxf = request.cookies.maxf
if not rightChoice(tip, sol) and curf < maxf:
if len(falseChars(ntip, sol)) > 0:
curf = int(curf) + 1
response.set_cookie("curf", str(curf))
curf = str(curf)
return "<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>" +\
'<span style="font-family:\'Source Code Pro\'">' + partSol(tip, sol) + '</span>' + "<br />" +\
"Faults " + curf + " / " + str(int(maxf)+1) + ": " + falseChars(tip, sol) +\
"<form action=\"/\" method=\"POST\">"+\
"<input type=\"text\" name=\"ntip\" maxlength=\"1\">"+\
"<input type=\"submit\" name=\"guess\" value=\"raten\"> <br />" +\
pics[int(curf)]
else:
response.set_cookie("tip", "", expires=0)
response.set_cookie("sol", "", expires=0)
response.set_cookie("curf", "", expires=0)
response.set_cookie("maxf", "", expires=0)
response.set_cookie("sessionid", "", expires=0)
if (rightChoice(tip, sol) and curf < maxf):
return '<p style="font-size:300px">勝ち</p><br />'
else:
return '<h1>負け・・・死んだ</h1>' + pics[int(maxf)]
run(host='localhost', port=8080)