From: Benjamin Mako Hill Date: Fri, 1 May 2015 17:14:23 +0000 (-0700) Subject: reverted the encoding fix that tommy made in lieu of a different crazy hack X-Git-Url: https://projects.mako.cc/source/twitter-api-cdsw-solutions/commitdiff_plain/c63b39e25aac93634380365407e6b909d19dcd4f?ds=inline reverted the encoding fix that tommy made in lieu of a different crazy hack - backed out the two changes to the tweepy code that was stripping non-unicode for all users - added a new module that checks if it's windows and, if so, enables the windows console fix - added the new encoding_fix module to each of the twitter examples --- diff --git a/encoding_fix.py b/encoding_fix.py new file mode 100644 index 0000000..d927bd1 --- /dev/null +++ b/encoding_fix.py @@ -0,0 +1,4 @@ +import os +if os.name == "nt": + import win_unicode_console + win_unicode_console.enable() diff --git a/tweepy/models.py b/tweepy/models.py index af80986..30456b2 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -75,13 +75,6 @@ class Status(Model): @classmethod def parse(cls, api, json): status = cls(api) - - # I'm not proud. Blame billg. - import sys - json['text'] = str(json['text'].encode(sys.stdout.encoding, 'replace'))[2:-1] - if 'user' in json: - json['user']['screen_name'] = str(json['user']['screen_name'].encode(sys.stdout.encoding, 'replace'))[2:-1] - setattr(status, '_json', json) for k, v in json.items(): if k == 'user': diff --git a/tweepy/streaming.py b/tweepy/streaming.py index faf42ea..9b246bd 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -268,10 +268,10 @@ class Stream(object): sleep(self.snooze_time) self.snooze_time = min(self.snooze_time + self.snooze_time_step, self.snooze_time_cap) - # except Exception as exc: - # exception = exc - # # any other exception is fatal, so kill loop - # break + except Exception as exc: + exception = exc + # any other exception is fatal, so kill loop + break # cleanup self.running = False diff --git a/twitter-stream-raw1.py b/twitter-stream-raw1.py index 2ed1403..b6ea13b 100644 --- a/twitter-stream-raw1.py +++ b/twitter-stream-raw1.py @@ -1,3 +1,4 @@ +import encoding_fix import json import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET diff --git a/twitter-stream1.py b/twitter-stream1.py index 87c548c..e94422d 100644 --- a/twitter-stream1.py +++ b/twitter-stream1.py @@ -1,3 +1,4 @@ +import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET diff --git a/twitter-stream2.py b/twitter-stream2.py index 8e1eee1..47855d8 100644 --- a/twitter-stream2.py +++ b/twitter-stream2.py @@ -1,3 +1,4 @@ +import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET diff --git a/twitter1.py b/twitter1.py index c1ec98f..26b6337 100644 --- a/twitter1.py +++ b/twitter1.py @@ -1,3 +1,4 @@ +import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET diff --git a/twitter2.py b/twitter2.py index 96a86fc..89f03fa 100644 --- a/twitter2.py +++ b/twitter2.py @@ -1,3 +1,4 @@ +import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET diff --git a/twitter3.py b/twitter3.py index d9b7ab7..16329e3 100644 --- a/twitter3.py +++ b/twitter3.py @@ -1,3 +1,4 @@ +import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET diff --git a/twitter4.py b/twitter4.py index 2bf35a6..918b565 100644 --- a/twitter4.py +++ b/twitter4.py @@ -1,3 +1,4 @@ +import encoding_fix import tweepy from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET