mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Restore get_all_users and get_all_mentionned in nested tweets
This commit is contained in:
parent
01dd93e076
commit
5cad4ab2a7
@ -120,6 +120,10 @@ def is_media(tweet):
|
|||||||
def get_all_mentioned(tweet, conf, field="screen_name"):
|
def get_all_mentioned(tweet, conf, field="screen_name"):
|
||||||
""" Gets all users that have been mentioned."""
|
""" Gets all users that have been mentioned."""
|
||||||
results = []
|
results = []
|
||||||
|
if hasattr(tweet, "retweeted_status"):
|
||||||
|
results.extend(get_all_mentionned(tweet.retweeted_status, conf, field))
|
||||||
|
if hasattr(tweet, "quoted_status"):
|
||||||
|
results.extend(tweet.quoted_status, conf, field)
|
||||||
if hasattr(tweet, "entities") and tweet.entities.get("user_mentions"):
|
if hasattr(tweet, "entities") and tweet.entities.get("user_mentions"):
|
||||||
for i in tweet.entities["user_mentions"]:
|
for i in tweet.entities["user_mentions"]:
|
||||||
if i["screen_name"] != conf["user_name"] and i["id_str"] != tweet.user:
|
if i["screen_name"] != conf["user_name"] and i["id_str"] != tweet.user:
|
||||||
@ -130,17 +134,19 @@ def get_all_mentioned(tweet, conf, field="screen_name"):
|
|||||||
def get_all_users(tweet, session):
|
def get_all_users(tweet, session):
|
||||||
string = []
|
string = []
|
||||||
user = session.get_user(tweet.user)
|
user = session.get_user(tweet.user)
|
||||||
if hasattr(tweet, "retweeted_status"):
|
|
||||||
string.append(user.screen_name)
|
|
||||||
tweet = tweet.retweeted_status
|
|
||||||
else:
|
|
||||||
if user.screen_name != session.db["user_name"]:
|
if user.screen_name != session.db["user_name"]:
|
||||||
string.append(user.screen_name)
|
string.append(user.screen_name)
|
||||||
|
if hasattr(tweet, "retweeted_status"):
|
||||||
|
string.extend(get_all_users(tweet.retweeted_status, session))
|
||||||
|
if hasattr(tweet, "quoted_status"):
|
||||||
|
string.extend(get_all_users(tweet.quoted_status, session))
|
||||||
if hasattr(tweet, "entities") and tweet.entities.get("user_mentions"):
|
if hasattr(tweet, "entities") and tweet.entities.get("user_mentions"):
|
||||||
for i in tweet.entities["user_mentions"]:
|
for i in tweet.entities["user_mentions"]:
|
||||||
if i["screen_name"] != session.db["user_name"] and i["screen_name"] != user.screen_name:
|
if i["screen_name"] != session.db["user_name"] and i["screen_name"] != user.screen_name:
|
||||||
if i["screen_name"] not in string:
|
if i["screen_name"] not in string:
|
||||||
string.append(i["screen_name"])
|
string.append(i["screen_name"])
|
||||||
|
# Attempt to remove duplicates, tipically caused by nested tweets.
|
||||||
|
string = list(dict.fromkeys(string))
|
||||||
if len(string) == 0:
|
if len(string) == 0:
|
||||||
string.append(user.screen_name)
|
string.append(user.screen_name)
|
||||||
return string
|
return string
|
||||||
|
Loading…
Reference in New Issue
Block a user