Skip to content

Commit

Permalink
Catch parse tweet bugs
Browse files Browse the repository at this point in the history
Is there not a library for this?
  • Loading branch information
StephanAkkerman committed Nov 16, 2023
1 parent c5d5d42 commit a6fcfd5
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/util/parse_tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ def parse_tweet(tweet: dict, update_tweet_id: bool = False):
# Media
media = []
media_types = []
if "extended_entities" in tweet["legacy"].keys():
if "media" in tweet["legacy"]["extended_entities"].keys():
media = [
image["media_url_https"]
for image in tweet["legacy"]["extended_entities"]["media"]
]
# photo, video
media_types = [
image["type"] for image in tweet["legacy"]["extended_entities"]["media"]
]
if "legacy" in tweet.keys():
if "extended_entities" in tweet["legacy"].keys():
if "media" in tweet["legacy"]["extended_entities"].keys():
media = [
image["media_url_https"]
for image in tweet["legacy"]["extended_entities"]["media"]
]
# photo, video
media_types = [
image["type"]
for image in tweet["legacy"]["extended_entities"]["media"]
]

# Remove t.co url from text
text = remove_twitter_url_at_end(tweet["legacy"]["full_text"])
Expand Down

0 comments on commit a6fcfd5

Please sign in to comment.