pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

alvinator private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Alvin Delagon on Fri 17 Apr 08:51 (modification of post by Alvin Delagon view diff)
report abuse | download | new post

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

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post