Unescape HTML entities in tweets and messages
authorBenjamin Rubin <bnrubin@gmail.com>
Sun, 20 Jul 2014 00:00:58 +0000 (20:00 -0400)
committerBenjamin Rubin <bnrubin@gmail.com>
Sun, 20 Jul 2014 00:00:58 +0000 (20:00 -0400)
rainbowstream/draw.py
rainbowstream/py3patch.py

index 96d2657..66c2483 100644 (file)
@@ -20,6 +20,11 @@ db = RainbowDB()
 g = {}
 
 
+def unescape(s):
+    p = HTMLParser()
+    return p.unescape(s)
+
+
 def init_cycle():
     """
     Init the cycle
@@ -147,7 +152,7 @@ def draw(t, iot=False, keyword=None, check_semaphore=False, fil=[], ig=[]):
     check_theme()
     # Retrieve tweet
     tid = t['id']
-    text = t['text']
+    text = unescape(t['text'])
     screen_name = t['user']['screen_name']
     name = t['user']['name']
     created_at = t['created_at']
@@ -267,7 +272,7 @@ def print_message(m):
     """
     sender_screen_name = '@' + m['sender_screen_name']
     sender_name = m['sender']['name']
-    text = m['text']
+    text = unescape(m['text'])
     recipient_screen_name = '@' + m['recipient_screen_name']
     recipient_name = m['recipient']['name']
     mid = m['id']
@@ -453,4 +458,4 @@ def print_list(group):
 
 
 # Start the color cycle
-start_cycle()
\ No newline at end of file
+start_cycle()
index 05fe7ff..6042984 100644 (file)
@@ -9,6 +9,13 @@ try:
 except:
     from io import StringIO, BytesIO
 
+# HTMLParser module
+
+try:
+    from HTMLParser import HTMLParser
+except:
+    from html.parser import HTMLParser
+
 # raw_input and map functiion behaviour
 if sys.version[0] == "3":
     raw_input = input