#!/usr/local/bin/python
# -*- coding: UTF-8 -*-

import Cookie
import cgi
import cgitb; cgitb.enable()  # for troubleshooting
import Player
import os
import glob

form = cgi.FieldStorage()
cookie = form.getvalue("user", "RandomUser")
C = Cookie.SimpleCookie()
C["username"] = cookie

s = 0
temp = []
flag = False
for i in open("scores.txt", "r"):
	temp.append(i)
	if i.split(" ")[0].strip() == cookie.strip():
		flag = True
		s = i.split(" ")[1]

if flag == False:
	temp.append("%s 1500\n"%cookie)
	s = 1500

toWrite = open("scores.txt", "w")
for i in temp:
	toWrite.write(i)
toWrite.close()
C["score"] = s
print C

print 'Location: http://students.washington.edu/zbadgerm/Math480/lobby.cgi\n'