]> projects.mako.cc - twitter-api-cdsw/commitdiff
reverted the encoding fix that tommy made in lieu of a different crazy hack
authorBenjamin Mako Hill <mako@atdot.cc>
Fri, 1 May 2015 17:14:23 +0000 (10:14 -0700)
committerBenjamin Mako Hill <mako@atdot.cc>
Fri, 1 May 2015 17:18:45 +0000 (10:18 -0700)
- 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

encoding_fix.py [new file with mode: 0644]
tweepy/models.py
tweepy/streaming.py
twitter-stream-raw1.py
twitter-stream1.py
twitter-stream2.py
twitter1.py
twitter2.py
twitter3.py
twitter4.py

diff --git a/encoding_fix.py b/encoding_fix.py
new file mode 100644 (file)
index 0000000..d927bd1
--- /dev/null
@@ -0,0 +1,4 @@
+import os
+if os.name == "nt":
+    import win_unicode_console
+    win_unicode_console.enable()
index af80986ba6b2bdc0e337567cf7f3ee608ca14ff6..30456b257cd95c7553ffebbd5920fdb199c14d82 100644 (file)
@@ -75,13 +75,6 @@ class Status(Model):
     @classmethod
     def parse(cls, api, json):
         status = cls(api)
     @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':
         setattr(status, '_json', json)
         for k, v in json.items():
             if k == 'user':
index faf42eacfa3724e73d2c1cbead877e53dba00deb..9b246bda820c5f2e5b31abcd3bf8b6570a7b2f93 100644 (file)
@@ -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)
                 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
 
         # cleanup
         self.running = False
index 2ed14032c52549f93e80ee6aa284ddd6e7d5312a..b6ea13bf321a8753ef3968924a32925bc7e4a4bf 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import json
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 import json
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
index 87c548c0093d61c9435b0957f5a54f7307a3fe27..e94422dd0f8dc43b3c99258755aa429cea3a17a6 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
index 8e1eee1c44f5e32f59eb194fd224fb1be3e65890..47855d8b657ba3ec813169f628337d95aa01d5b3 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
index c1ec98fc81dacd04942db5ae7dc88e5fcd660965..26b6337cf3247f8d9f14d6f8930e60f97c24a8e9 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
index 96a86fc764fede2a122059576f27c229faee1d51..89f03fabebc2b99661ce5f29dc6973e4e1d09a18 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
index d9b7ab7e844d99085a076056921a8c72387821a3..16329e355c65ecae86a1405d1e08d46d77b351d9 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
index 2bf35a64440283c206065c098e884d689c0cf346..918b565b37fa8af34b11efd8339c5f6dcf25c0a5 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 

Benjamin Mako Hill || Want to submit a patch?