#!/usr/bin/python import cgi import random # Header print "Content-Type: text/html" print print "DiceRoller 0.0.1" print "

Simple Diceroller - Now With Chat!

" # Function which allow you to write a message to the chat def writeChat(): # msgs = open("chat.txt","w") print "
" print "" print "" print "
" form = cgi.FieldStorage() msg = form["message"].value if (msg != "" and msg != " "): print "Message:", msg # msgs.write("msg") # msgs.close() # Function which shows text in a file - all the messages def readChat(): global msgs msgs = open("chat.txt","r") filedata = msgs.readlines() for msgs in filedata: print msgs,"
" print "
" msgs.close() writeChat() # Function which return an integer between 1 and 6 def rollDice(): eyes = random.randint(1,6) print "Dice show",eyes,"eyes
" # Function which return rollDice() four times def showDices(): for i in range(0,4): rollDice() # Run script showDices() print "

" readChat() msgs.close()