-
Notifications
You must be signed in to change notification settings - Fork 0
/
games.py
84 lines (84 loc) · 3.18 KB
/
games.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
#!/Users/tomar/Anaconda3/python.exe
"""
Created on Sat May 27 16:34:21 2017 by tomar
#!/usr/bin/python3
#!/Users/tomar/Anaconda3/python.exe
IMPORTANT: this needs to be redone as an admin only page, not available from the site (11/20/2019)
"""
import sys
try:
import gUtils
import Users
except:
sys.path.append("..")
import gUtils
import Users
import utils
import cgi
import random
import json
print("Content-type: text/html \n")
print('''
<html><head><title>Shanghai Game History</title>
<script src="/python/utils.js"></script>
<LINK REL='StyleSheet' HREF='/python/songs.css?{}' TYPE='text/css' TITLE='ToMarStyle' MEDIA='screen'>
<LINK REL='StyleSheet' HREF='/python/tomar.css?{}' TYPE='text/css' TITLE='ToMarStyle' MEDIA='screen'>
<link href='//fonts.googleapis.com/css?family=Didact Gothic' rel='stylesheet'>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="932688745244-i4vfeap5jgu8id5dagrc49786vvs0qrf.apps.googleusercontent.com">
'''.format(random.randrange(9999), random.randrange(9999)))
gUtils.goTo()
gUtils.toggleDiv()
form = cgi.FieldStorage() # instantiate only once!
gid = form.getvalue('gId', '') #remove default
name = form.getvalue('gName', '') #remove default
gMail = form.getvalue('gMail', '') #remove default
gImg = form.getvalue('gImage', '') #remove default
oper = form.getvalue('oper','')
print('''
<form name="gForm" method="POST" action="#">
<input type="hidden" name="gId" value="{}">
<input type="hidden" name="gName" value="{}">
<input type="hidden" name="gMail" value="{}">
<input type="hidden" name="gImage" value="{}">
<input type="hidden" name="oper">
</form>
'''.format(gid, name, gMail, gImg))
#gid = "106932376942135580175"
if gid == '':
gUtils.googleSignIn()
else:
users = Users.Users()
authS = users.authenticate(gid, name, gMail, gImg, users.SHANGHAI) # gets you into shanghai
authA = users.authenticate(gid, name, gMail, gImg, users.ADMIN)
print(authS[1])
if authS[0] == '1':
with open("games.json") as gData:
games = json.load(gData)
gDict = {}
for g in games:
id = g["I"]
if (id in gDict):
gDict[id].append((g["T"], g["M"]))
else:
gDict[id] = [((g["T"], g["M"]))]
if authA[0] == '1':
for u in sorted(gDict):
print('''<br><a class="textL" style="color: blue; font-size: 1.2em;" href="javascript:'" ''')
print(''' onClick=javascript:toggleDiv("div{}")>{} ({})</a>'''.format(u, u, len(gDict[u])))
print('''<div id="div{}" style="display:none;";>'''.format(u))
print('''<table border=0><tr><th>Date</th><th>Moves</th>''')
for g in gDict[u]:
print('''<tr><td>{}</td><td class="textR">{}</td></tr>'''.format(utils.formatDate(g[0][0:8]), g[1]))
print('''</table>''')
print('''</div>''')
else:
print('''<table border=0><tr><th>Date</th><th>Moves</th>''')
for g in gDict[gid]:
print('''<tr><td>{}</td><td class="textR">{}</td></tr>'''.format(utils.formatDate(g[0][0:8]), g[1]))
print('''</table>''')
else:
print('''
Welcome to ToMarGames Friends and Family!<br><br>It looks like you've landed on a page you don't have permission to access.
''')
print('</body></html>')