#!/usr/bin/python
import cgi
import random
# Header
print "Content-Type: text/html"
print
print "<title>DiceRoller 0.0.1</title>"
print "<h1>Simple Diceroller - Now With Chat!</h1>"
# Function which allow you to write a message to the chat
def writeChat():
print "<form action='diceroller.py' method='send'>"
print "<input type='text' name='message' />"
print "<input type='submit' value='Send' />"
print "</form>"
form = cgi.FieldStorage()
msg = form["message"].value
if (msg != "" or msg != " "):
print "Message:", form['message'].value
# Function which shows text in a file - all the messages
def readChat():
file = open("chat.txt","r")
for line in file:
print line,"<br />"
print "<br />"
writeChat()
# Function which return an integer between 1 and 6
def rollDice():
eyes = random.randint(1,6)
print "Dice show",eyes,"eyes<br />"
# Function which return rollDice() four times
def showDices():
for i in range(0,4):
rollDice()
# Run script
showDices()
print "<br /><br />"
readChat()
file.close()