Comment out the twitter test code.
authorScott Gasch <[email protected]>
Wed, 8 Feb 2023 18:20:05 +0000 (10:20 -0800)
committerScott Gasch <[email protected]>
Wed, 8 Feb 2023 18:20:05 +0000 (10:20 -0800)
twitter_renderer.py

index 288eea16916eaaf1096d3cc6a6890ac015743db2..23c36f87131d64a12591f84f5c2e7b012a2479c8 100644 (file)
@@ -69,10 +69,10 @@ class twitter_renderer(renderer.abstaining_renderer):
             print("Exception while fetching tweets!")
             return False
         for tweet in tweets:
-            #j = tweet._json
-            #import json
-            #print(json.dumps(j, indent=4, sort_keys=True))
-            #print("------")
+            # j = tweet._json
+            # import json
+            # print(json.dumps(j, indent=4, sort_keys=True))
+            # print("------")
 
             author = tweet.author.name
             author_handle = tweet.author.screen_name
@@ -84,23 +84,23 @@ class twitter_renderer(renderer.abstaining_renderer):
         return True
 
     def get_hashtags(self, tweet) -> str:
-        ret = ' '
-        if 'entities' in tweet._json:
-            entities = tweet._json['entities']
-            if 'hashtags' in entities:
-                for x in entities['hashtags']:
+        ret = " "
+        if "entities" in tweet._json:
+            entities = tweet._json["entities"]
+            if "hashtags" in entities:
+                for x in entities["hashtags"]:
                     ret += f'<B>#{x["text"]}</B>, '
-        ret = re.sub(', $', '', ret)
+        ret = re.sub(", $", "", ret)
         return ret
 
     def get_media_url(self, tweet) -> Optional[str]:
-        if 'entities' in tweet._json:
-            entities = tweet._json['entities']
-            if 'media' in entities:
-                media = entities['media']
+        if "entities" in tweet._json:
+            entities = tweet._json["entities"]
+            if "media" in entities:
+                media = entities["media"]
                 for x in media:
-                    if 'media_url_https' in x:
-                        return x['media_url_https']
+                    if "media_url_https" in x:
+                        return x["media_url_https"]
         return None
 
     def shuffle_tweets(self) -> bool:
@@ -124,11 +124,11 @@ class twitter_renderer(renderer.abstaining_renderer):
                 ):
                     already_seen.add(text)
                     text = self.linkify(text)
-                    text = f'<B>{text}</B>'
+                    text = f"<B>{text}</B>"
                     text += self.get_hashtags(tweet)
                     media_url = self.get_media_url(tweet)
                     if media_url:
-                        text = f'<TABLE WIDTH=100%><TD WITDH=70%>{text}</TD>'
+                        text = f"<TABLE WIDTH=100%><TD WITDH=70%>{text}</TD>"
                         text += f'<TD><IMG SRC="{media_url}" WIDTH=200></TD></TABLE>'
                     f.write(f"<LI>{text}")
                     count += 1
@@ -140,13 +140,13 @@ class twitter_renderer(renderer.abstaining_renderer):
 
 
 # Test
-t = twitter_renderer(
-    {"Fetch Tweets" : 1,
-     "Shuffle Tweets" : 1})
-#x = "bla bla bla https://t.co/EjWnT3UA9U bla bla"
-#x = t.linkify(x)
-#print(x)
-if t.fetch_tweets() == 0:
-    print("Error fetching tweets, none fetched.")
-else:
-    t.shuffle_tweets()
+t = twitter_renderer(
+#    {"Fetch Tweets" : 1,
+#     "Shuffle Tweets" : 1})
+# x = "bla bla bla https://t.co/EjWnT3UA9U bla bla"
+# x = t.linkify(x)
+# print(x)
+if t.fetch_tweets() == 0:
+#    print("Error fetching tweets, none fetched.")
+else:
+#    t.shuffle_tweets()