Share Pastebin
Guest
Public paste!

Alvin Delagon

By: a guest | Apr 17th, 2009 | Syntax: Python | Size: 1.62 KB | Hits: 98 | Expires: Never
Copy text to clipboard
  1. import cherrypy
  2. import time
  3.  
  4. class TweetEntry:
  5.     def __init__(self, subject, author, content):
  6.         self.subject = subject
  7.         self.author = author
  8.         self.content = content
  9.         self.tstamp = time.strftime("%Y-%m-%d %H:%M:%S")
  10.  
  11.     def prettyPrint(self):
  12.         s  = "<b>Subject: </b>%s<br/>" % (self.subject)
  13.         s += "<b>By: </b>%s<br/>" % (self.author)
  14.         s += "<b>At: </b>%s<br/>" % (self.tstamp)
  15.         s += "<b>Tweet: </b><br/>%s<br/>" % (self.content)
  16.         return (s)
  17.    
  18. class Tweet:
  19.     tweets = []
  20.     def index(self):
  21.         disp = "<h1>Welcome to Simple Twitter 1.0.0</h1>"
  22.         disp += "<form action='edit' method='POST'><input type='submit' value='New Post'/><br/><br/>"
  23.         for tweet in self.tweets:
  24.             disp += tweet.prettyPrint() + "<br/><br/>"
  25.         return (disp)
  26.     index.exposed = True
  27.    
  28.     def edit(self):
  29.         return ("""
  30.        <h1>Compose new Tweet</h1>
  31.        <form action='publish' method='POST'>
  32.        Subject: <input type='text' name='subject' size='25'><br/><br/>
  33.        Author Name: <input type='text' name='author' size='25'><br/><br/>
  34.        Content: <br/><textarea name='content' rows=5 cols=80></textarea><br/><br/>
  35.        <input type='submit' value='Tweet!'/>
  36.        </form>
  37.        <br/>
  38.        """)
  39.     edit.exposed = True
  40.  
  41.     def publish(self, subject, author, content):
  42.         self.tweets.append(TweetEntry(subject, author, content))
  43.         return ("""<meta http-equiv='REFRESH' content='0;url=index'>""")
  44.     publish.exposed = True
  45.  
  46. cherrypy.server.socket_port = 8000
  47. cherrypy.quickstart(Tweet())