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
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:
):
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
# 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()