# HG changeset patch # User Raphael Velt # Date 1318253052 -7200 # Node ID e26d4354b578b9e526b49ba01481a30cb29f4477 # Parent 8e7f49582714a2ae8cd2795692b1ed1af951cc54 Modifications mineures diff -r 8e7f49582714 -r e26d4354b578 tweetcast/server/tweetcast-gevent.py --- a/tweetcast/server/tweetcast-gevent.py Mon Oct 10 11:55:03 2011 +0200 +++ b/tweetcast/server/tweetcast-gevent.py Mon Oct 10 15:24:12 2011 +0200 @@ -24,21 +24,33 @@ user_id = Column(Integer, ForeignKey('tweet_user.id')) user = relationship("User", backref="tweets") - def __repr__(self): - return anyjson.serialize({ + def jsondict(self): + return { "id" : str(self.id), "created_at" : str(self.created_at), "text" : self.text, - "user_id" : self.user_id, - "screen_name" : self.user.screen_name - }) + "user" : self.user.jsondict() + } + + def __repr__(self): + return anyjson.serialize(self.jsondict()) class User(Base): __tablename__ = "tweet_user" id = Column(BigInteger, primary_key=True, autoincrement=False) - created_at = Column(DateTime) screen_name = Column(String, index=True) + profile_image_url = Column(String) + + def jsondict(self): + return { + "id" : str(self.id), + "screen_name" : self.screen_name, + "profile_image_url" : self.profile_image_url + } + + def __repr__(self): + return anyjson.serialize(self.jsondict()) class TweetCast(object): diff -r 8e7f49582714 -r e26d4354b578 tweetcast/server/tweetcast.py --- a/tweetcast/server/tweetcast.py Mon Oct 10 11:55:03 2011 +0200 +++ b/tweetcast/server/tweetcast.py Mon Oct 10 15:24:12 2011 +0200 @@ -8,8 +8,8 @@ from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol connectstring = "dbname='tweet_live' user='postgres' host='localhost' password='doiteshimashite'" -columns = [ 'id', 'created_at', 'text', 'user_id', 'screen_name' ] -selectcommon = "SELECT tweet_tweet.id, tweet_tweet.created_at, text, user_id, screen_name FROM tweet_tweet JOIN tweet_user ON tweet_tweet.user_id = tweet_user.id" +columns = [ 'id', 'created_at', 'text', 'user_id', 'screen_name', 'profile_image_url' ] +selectcommon = "SELECT tweet_tweet.id, tweet_tweet.created_at, text, user_id, screen_name, profile_image_url FROM tweet_tweet JOIN tweet_user ON tweet_tweet.user_id = tweet_user.id" dbpool = adbapi.ConnectionPool("psycopg2",connectstring)