#!/usr/bin/env python
# -*- coding: utf-8 -*-

comment=""
reply=""

try:
    # read the file 
    myfile = open('cgi-bin/light.dat','r')
    comment=myfile.read(1)
    myfile.close()
    if comment=="n":
        comment="f"
        reply="off"
    else:
        comment="n"
        reply="on"
except:
    # no file
    comment="n"
    reply="on"
    
myfile = open('cgi-bin/light.dat','w')
myfile.write(comment)
myfile.close()

# display page
print "Content-Type: text/html"
print """
<HEAD>
<TITLE>Internet LED control</TITLE>
<meta name="viewport" content="width=100" content="initial-scale=1">
</HEAD>
<html>
<body> 
The LED is now %s
</body>
</html>
""" % reply
