-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.py
58 lines (56 loc) · 1.73 KB
/
score.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
#!/usr/bin/env python3
from time import sleep
key = [1,1,1]
while(True):
try:
players = {}
playerScore = {}
a = open("log.txt","r")
lines = a.read().split('\n')
lines.pop(0)
lines.pop()
a.close()
for line in lines:
name = line.split(' ')[0]
if(not name in players):
players[name] = []
players[name].append(line.split(' ')[1])
for player in players:
playerScore[player] = 0
for i in range(3):
if(key[i] == int(players[player][i])):
playerScore[player] += 1
print(playerScore)
a = open("/var/www/html/end.html","r")
web = a.read()
webLines = web.split("\n")
buf = "<ol>\n"
for player in playerScore:
buf += "<li>" + player + " scored " + str(playerScore[player]) + "</li>" + '\n'
buf += "\n</ol>\n"
startln = 0
endln = 0
#print(webLines)
for num in range(len(webLines)):
if(webLines[num].replace("\t","").replace(" ","") == "<ol>"):
startln = num
if(webLines[num].replace("\t","").replace(" ","") == "</ol>"):
endln = num
#print(startln, endln)
#print(webLines[startln],webLines[endln])
a.close()
out = ""
for i in range(len(webLines)):
if(i == startln):
out += buf
elif(i >startln and (i <=endln)):
continue
else:
out += webLines[i] + "\n"
a = open("/var/www/html/end.html","w")
a.write(out)
a.close()
sleep(1)
except:
print("Waiting...")
sleep(2)