SHARE
TWEET

Alvin Delagon

a guest Apr 17th, 2009 377 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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())
RAW Paste Data
Want to get better at Python?
Learn to code Python in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top