Modifications mineures
authorRaphael Velt <raph.velt@gmail.com>
Mon, 10 Oct 2011 15:24:12 +0200
changeset 309 e26d4354b578
parent 308 8e7f49582714
child 310 526d3e411736
Modifications mineures
tweetcast/server/tweetcast-gevent.py
tweetcast/server/tweetcast.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):
 	
--- 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)