Subdomain Posts
XML | 2 days ago
XML | 2 days ago
None | 22 days ago
Python | 30 days ago
Python | 337 days ago
Python | 337 days ago
Python | 337 days ago
XML | 342 days ago
C | 342 days ago
C | 345 days ago
Recent Posts
None | 11 sec ago
None | 22 sec ago
HTML | 34 sec ago
OCaml | 38 sec ago
HTML | 40 sec ago
None | 44 sec ago
None | 45 sec ago
JavaScript | 56 sec ago
OCaml | 58 sec ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Alvin Delagon on the 17th of Apr 2009 08:47:50 AM Download | Raw | Embed | Report
  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())
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: