-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice
executable file
·49 lines (41 loc) · 1.29 KB
/
dice
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
#!/usr/bin/env python3
from aiohttp import web
import random
def pattern(dice):
dit_class={ True: 'dit filled', False: 'dit' }
return map(lambda x : dit_class[x], (
dice > 1, dice > 7, dice > 3,
dice > 5, dice % 2 == 1, dice > 5,
dice > 1, dice == 8, dice > 3,
))
def web_page(dice):
tl, tm, tr, ml, mm, mr, bl, bm, br = pattern(dice)
style="""
body { font-size: x-large; }
.dice { display: grid; grid-template-columns: 4rem 4rem 4rem;
grid-gap: 1.6rem; padding: 4rem; }
.filled { background: red; border-radius: 2rem; }
.dit { height: 4rem; }
"""
return f"""<!DOCTYPE html>
<html>
<header>
<title>Dice throw</title>
<style>{style}</style>
</header>
<body>
<p>Dice roll is {dice}</p>
<div class="dice">
<div class="{tl}"></div><div class="{tm}"></div><div class="{tr}"></div>
<div class="{ml}"></div><div class="{mm}"></div><div class="{mr}"></div>
<div class="{bl}"></div><div class="{bm}"></div><div class="{br}"></div>
</div>
</body>
</html>
"""
async def hello(request):
dice = random.randrange(1, 9)
return web.Response(text=web_page(dice), content_type="text/html")
app = web.Application()
app.add_routes([web.get('/', hello)])
web.run_app(app, port=8080)