#!/usr/local/bin/python
# -*- coding: UTF-8 -*-

import Cookie
import cgi
import cgitb; cgitb.enable()  # for troubleshooting
import Player
import os
import glob

thecookie = os.environ.get('HTTP_COOKIE')
C1 = Cookie.SimpleCookie()
C1.load(thecookie)
me = C1["username"].value

C = Cookie.SimpleCookie()

bf = ""
for i in glob.glob("*.txt"):
	if i.split(".")[0].startswith(me) or i.split(".")[0].endswith(me):
		bf = i
		C["field"] = bf.split(".")[0]

for i in open(bf, "r"):
	if not i.strip().startswith(me):
		C["enemy"] = i.split("|")[0].strip()

print C

print 'Location: http://students.washington.edu/zbadgerm/Math480/setships.cgi\n'
		