update lookup functions

This commit is contained in:
Mylloon 2022-08-07 17:24:42 +02:00
parent a2e118c38f
commit c0b5c168a7
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

23
main.py
View file

@ -85,7 +85,7 @@ class Listener(StreamingClient):
"users": users, "users": users,
"forcelist": forcelist "forcelist": forcelist
} }
self.listOfFriendsID = getFriendsID(client, users) + getIDs(client, forcelist) self.victim_list = getFriends(client, users) + getIDs(client, forcelist)
def on_connect(self): def on_connect(self):
if self.accounts['forcelist'] == []: if self.accounts['forcelist'] == []:
@ -101,9 +101,11 @@ class Listener(StreamingClient):
print(f"Raison : {notice['reason']}") print(f"Raison : {notice['reason']}")
def on_status(self, status): def on_status(self, status):
print(status)
exit(0)
json = status._json json = status._json
# Verify the author of the tweet # Verify the author of the tweet
if json["user"]["id"] in self.listOfFriendsID and json["user"]["screen_name"] not in keys["WHITELIST"]: if json["user"]["id"] in self.victim_list and json["user"]["screen_name"] not in keys["WHITELIST"]:
# Verify the age of the tweet # Verify the age of the tweet
if seniority(json["created_at"]): if seniority(json["created_at"]):
# Verify if the tweet isn't a retweet # Verify if the tweet isn't a retweet
@ -198,23 +200,22 @@ def repeater(word: str) -> str:
# Random format from the base answer # Random format from the base answer
return createBaseAnswers(word) return createBaseAnswers(word)
def getFriendsID(client: Client, users: list[str]) -> list: def getFriends(client: Client, users: list[str]) -> list:
"""Get all friends of choosen users""" """Get all friends of choosen users"""
liste = [] friends_list = []
# Get IDs of the user's friends # Get IDs of the user's friends
for user in users: for user in users:
# TODO: Update Twitter API V2 user_id = client.get_user(username=user, user_auth=True).data.id
liste.extend(client.get_friend_ids(screen_name=user)) friends_list.extend(client.get_users_following(id=user_id, user_auth=True))
return list(set(liste)) return friends_list[0]
def getIDs(client: Client, users: list[str]) -> list: def getIDs(client: Client, users: list[str]) -> list:
"""Get all the ID of users""" """Get all the ID of users"""
liste = [] users_list = []
# Get IDs of the users # Get IDs of the users
for user in users: for user in users:
# TODO: Update Twitter API V2 users_list.append(client.get_user(username=user, user_auth=True).data)
liste.append(client.get_user(screen_name=user)._json["id"]) return users_list
return list(set(liste))
def seniority(date: str) -> bool: def seniority(date: str) -> bool:
"""Return True only if the given string date is less than one day old""" """Return True only if the given string date is less than one day old"""