From 72c02928f45228d75ff391394800355ecd65e94e Mon Sep 17 00:00:00 2001 From: Vu Nhat Minh Date: Wed, 2 Jul 2014 17:26:15 +0900 Subject: [PATCH] stream config --- rainbowstream/colorset/default.json | 4 +++ rainbowstream/config.py | 8 ++++++ rainbowstream/rainbow.py | 38 ++++++++++++++++------------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/rainbowstream/colorset/default.json b/rainbowstream/colorset/default.json index 7d7aad7..bb9ff1c 100644 --- a/rainbowstream/colorset/default.json +++ b/rainbowstream/colorset/default.json @@ -17,6 +17,10 @@ // Image config "IMAGE_SHIFT" : "10", "IMAGE_MAX_HEIGHT" : "40", + // Stream config + "USER_DOMAIN" : "userstream.twitter.com", + "PUBLIC_DOMAIN" : "stream.twitter.com", + "SITE_DOMAIN" : "sitestream.twitter.com", // Color config "TWEET" : { diff --git a/rainbowstream/config.py b/rainbowstream/config.py index 55fea3c..e2937ca 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -1,6 +1,8 @@ import json +import re import os import os.path +from twitter.util import printNicely # Regular expression for comments comment_re = re.compile( @@ -22,6 +24,12 @@ def load_config(filepath): except: pass +DOMAIN = USER_DOMAIN + +# Image config +IMAGE_SHIFT = 10 +IMAGE_MAX_HEIGHT = 40 + # Load colorset default_config = 'rainbowstream/colorset/default.json' rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json' diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index bc791b4..e6488f0 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -1074,23 +1074,27 @@ def stream(domain, args, name='Rainbow Stream'): tweet_iter = stream.statuses.sample() # Iterate over the stream. - for tweet in tweet_iter: - if tweet is None: - printNicely("-- None --") - elif tweet is Timeout: - printNicely("-- Timeout --") - elif tweet is HeartbeatTimeout: - printNicely("-- Heartbeat Timeout --") - elif tweet is Hangup: - printNicely("-- Hangup --") - elif tweet.get('text'): - draw( - t=tweet, - iot=args.image_on_term, - keyword=args.track_keywords, - fil=args.filter, - ig=args.ignore, - ) + try: + for tweet in tweet_iter: + if tweet is None: + printNicely("-- None --") + elif tweet is Timeout: + printNicely("-- Timeout --") + elif tweet is HeartbeatTimeout: + printNicely("-- Heartbeat Timeout --") + elif tweet is Hangup: + printNicely("-- Hangup --") + elif tweet.get('text'): + draw( + t=tweet, + iot=args.image_on_term, + keyword=args.track_keywords, + fil=args.filter, + ig=args.ignore, + ) + except: + printNicely(magenta("I'm afraid we have problem with twitter'S maximum connection.")) + printNicely(magenta("Let's try again later.")) def fly(): -- 2.25.1