AbstractBeliefs

index.py

May 15th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. ####### index.py #########
  2.  
  3. import cgi, cgitb
  4. cgitb.enable()
  5.  
  6. import template
  7.  
  8. print template.start
  9. print template.header
  10. print "Welcome to the IRC Quote DB"
  11. print template.footer
  12.  
  13. ###### submit.py #######
  14.  
  15. import cgi, cgitb
  16. cgitb.enable()
  17.  
  18. import template
  19.  
  20. formcontent = cgi.FieldStorage()
  21. if "content" not in formcontent:
  22.     content = """\
  23. <form method="post" action="submit.py">
  24. <textarea rows="20" cols="80" name="content">
  25. </textarea>
  26. <input type="submit" value="Submit!">
  27. </form>"""
  28.  
  29. if "content" in formcontent:
  30.     import MySQLdb as sql
  31.     db = sql.connect(host='localhost', user=template.user, passwd=template.pasw, db=template.database)
  32.     cursor = db.cursor()
  33.     cursor.execute("INSERT INTO quotes (content, score, moderated) VALUES(%s, %s, %s)", (formcontent['content'].value, 0, 0))
  34.     content = """ Thank you, your quote has been added!"""
  35.     db.close()
  36.  
  37. print template.start
  38. print template.header
  39. print content
  40. print template.footer
  41.  
  42. ###### template.py ######
  43.  
  44. user = "quotes"
  45. pasw = "--------"
  46. database = "quotes"
  47. table = "quotes"
  48.  
  49. start = "Content-Type: text/html\n\n"
  50. header = """\
  51. <html>
  52.  
  53. <head>
  54.     <title> IRC Quotes DB </title>
  55. </head>
  56.  
  57. <body>
  58.     <a href="./index.py"> Home </a> /
  59.     <a href="./submit.py"> Submit </a> /
  60.     <a href="./quotes.py?grab=mostrecent"> Most Recent </a> /
  61.     <a href="./quotes.py?grab=top100"> Top 100 </a> /
  62.    
  63.     <br />"""
  64.  
  65. footer = """\
  66.     <br />
  67. </body>
  68. </html>"""
Advertisement
Add Comment
Please, Sign In to add comment