Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import cgi
- import cgitb
- cgitb.enable()
- from src import quotes
- HTMLSTR = """\
- <html>
- <head>
- <title>Quoets</title>
- <style type="text/css">
- #quoteform
- {{
- font-family:liberation sans,dejavu sans,arial,sans-serif;
- font-size:14pt
- }}
- #quoteindent
- {{
- position:relative;
- left:30px;
- top:8px;
- }}
- </style>
- </head>
- <body>
- <form name="inputquote" id="quoteform" action="quotes.py">
- Choose a specific quote ('list' = list all quote names, 'all' = all quotes, 'rand' = random quote):<br>
- <div id="quoteindent">
- <input type="text" name="quote" size="10" />
- <input type="submit" value="Submit">
- </div>
- </form>
- <p />
- <hr>
- <p />
- {0}
- </body>
- </html>
- """
- if __name__ == "__main__":
- print("Content-type: text/html\n\n")
- form = cgi.FieldStorage()
- lolquotes = quotes.QuotesHolder()
- lolquotes.populateFromDir()
- if "quote" not in form:
- quoteText = "No quote specified<p>"
- else:
- choice = form["quote"].value
- choice = choice.lower()
- if choice == "all":
- quoteText = str(lolquotes)
- elif choice == "rand":
- quoteText = str(lolquotes.randQuote())
- elif choice == "list":
- quoteText = lolquotes.listing()
- elif lolquotes.hasQuote(choice):
- quoteText = lolquotes.quotes[choice].rawPost
- else:
- quoteText = "Quote not found<p>"
- print(HTMLSTR.format(quoteText))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement