Advertisement
ijontichy

quotes.py

May 23rd, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import cgi
  4. import cgitb
  5. cgitb.enable()
  6.  
  7. from src import quotes
  8.  
  9. HTMLSTR = """\
  10. <html>
  11.  <head>
  12.    <title>Quoets</title>
  13.    <style type="text/css">
  14. #quoteform
  15. {{
  16.    font-family:liberation sans,dejavu sans,arial,sans-serif;
  17.    font-size:14pt
  18. }}
  19.  
  20. #quoteindent
  21. {{
  22.    position:relative;
  23.    left:30px;
  24.    top:8px;
  25. }}
  26.    </style>
  27.  </head>
  28.  <body>
  29. <form name="inputquote" id="quoteform" action="quotes.py">
  30.  
  31. Choose a specific quote ('list' = list all quote names, 'all' = all quotes, 'rand' = random quote):<br>
  32. <div id="quoteindent">
  33. <input type="text" name="quote" size="10" />
  34. <input type="submit" value="Submit">
  35. </div>
  36. </form>
  37. <p />
  38. <hr>
  39. <p />
  40. {0}
  41.  </body>
  42. </html>
  43. """
  44.  
  45. if __name__ == "__main__":
  46.     print("Content-type: text/html\n\n")
  47.  
  48.     form = cgi.FieldStorage()
  49.     lolquotes = quotes.QuotesHolder()
  50.     lolquotes.populateFromDir()
  51.  
  52.     if "quote" not in form:
  53.         quoteText = "No quote specified<p>"
  54.     else:
  55.         choice = form["quote"].value
  56.         choice = choice.lower()
  57.        
  58.         if choice == "all":
  59.             quoteText = str(lolquotes)
  60.  
  61.         elif choice == "rand":
  62.             quoteText = str(lolquotes.randQuote())
  63.  
  64.         elif choice == "list":
  65.             quoteText = lolquotes.listing()
  66.  
  67.         elif lolquotes.hasQuote(choice):
  68.             quoteText = lolquotes.quotes[choice].rawPost
  69.  
  70.         else:
  71.             quoteText = "Quote not found<p>"
  72.            
  73.            
  74.     print(HTMLSTR.format(quoteText))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement