Compare commits

...

2 commits

Author SHA1 Message Date
d3be698c66
* respect twitter API
* add some types
2022-08-06 01:50:53 +02:00
d0fe982083
update dotenv and pytz 2022-08-06 01:50:29 +02:00
2 changed files with 23 additions and 9 deletions

28
main.py
View file

@ -7,7 +7,6 @@ from datetime import datetime
from pytz import timezone from pytz import timezone
from queue import Queue from queue import Queue
from json import loads from json import loads
from itertools import product
def load(variables) -> dict: def load(variables) -> dict:
"""Load environment variables""" """Load environment variables"""
@ -163,7 +162,7 @@ class Listener(StreamListener):
print("\n") print("\n")
return False return False
def getFriendsID(api: API, users: list) -> list: def getFriendsID(api: API, users: list[str]) -> list:
"""Get all friends of choosen users""" """Get all friends of choosen users"""
liste = [] liste = []
# Get IDs of the user's friends # Get IDs of the user's friends
@ -171,7 +170,7 @@ def getFriendsID(api: API, users: list) -> list:
liste.extend(api.friends_ids(user)) liste.extend(api.friends_ids(user))
return list(set(liste)) return list(set(liste))
def getIDs(api: API, users: list) -> list: def getIDs(api: API, users: list[str]) -> list:
"""Get all the ID of users""" """Get all the ID of users"""
liste = [] liste = []
# Get IDs of the users # Get IDs of the users
@ -190,22 +189,37 @@ def seniority(date: str) -> bool:
# False if older than a day, else True # False if older than a day, else True
return False if age.days >= 1 else True return False if age.days >= 1 else True
def generateWords(array: list) -> list: def generateWords(array: list[str]) -> list:
""" """
Retrieves all possible combinations for the given list and returns the result as a list Retrieves all possible combinations for the given list and returns the result as a list
This is used for the filter in the stream (before calling the Listener) This is used for the filter in the stream (before calling the Listener::on_status)
""" """
quoiListe = [] quoiListe = []
for text in array: for text in array:
# Add all combinations # Add all combinations
# Example for 'oui': ['OUI', 'OUi', 'OuI', 'Oui', 'oUI', 'oUi', 'ouI', 'oui'] # Example for 'oui': ['OUI', 'OUi', 'OuI', 'Oui', 'oUI', 'oUi', 'ouI', 'oui']
quoiListe.extend(list(map(''.join, product(*zip(text.upper(), text.lower()))))) #
# -> Depends on: from itertools import product
# -> Problem : Create a too long list (+1000 words, max is 400)
# -> Cf. https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/overview
#
# quoiListe.extend(list(map(''.join, product(*zip(text.upper(), text.lower())))))
if text.lower() not in quoiListe:
# Word in lowercase
quoiListe.append(text.lower())
if text.upper() not in quoiListe:
# Word in uppercase
quoiListe.append(text.upper())
if text.capitalize() not in quoiListe:
# Word capitalized
quoiListe.append(text.capitalize())
return quoiListe return quoiListe
def createBaseTrigger(lists: list) -> list: def createBaseTrigger(lists: list[list]) -> list:
"""Merges all given lists into one""" """Merges all given lists into one"""
listing = [] listing = []
for liste in lists: for liste in lists:

View file

@ -1,3 +1,3 @@
python-dotenv==0.18.0 python-dotenv==0.20.0
tweepy==3.10.0 tweepy==3.10.0
pytz==2021.1 pytz==2022.1