From 4b60a79e492081aa4e5dc1df293d5029880dc82c Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sun, 27 Jun 2021 18:04:26 -0500 Subject: [PATCH] Made get_all_mentioned to take into account sometimes tweets might have no entities defined --- src/sessions/twitter/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sessions/twitter/utils.py b/src/sessions/twitter/utils.py index a9685212..10ba9c37 100644 --- a/src/sessions/twitter/utils.py +++ b/src/sessions/twitter/utils.py @@ -100,10 +100,11 @@ def is_media(tweet): def get_all_mentioned(tweet, conf, field="screen_name"): """ Gets all users that have been mentioned.""" results = [] - for i in tweet.entities["user_mentions"]: - if i["screen_name"] != conf["user_name"] and i["id_str"] != tweet.user: - if i.get(field) not in results: - results.append(i.get(field)) + if hasattr(tweet, "entities") and tweet.entities.get("user_mentions"): + for i in tweet.entities["user_mentions"]: + if i["screen_name"] != conf["user_name"] and i["id_str"] != tweet.user: + if i.get(field) not in results: + results.append(i.get(field)) return results def get_all_users(tweet, session):