Fix bug + opti api
This commit is contained in:
parent
a48f748bbe
commit
01ebc032b1
1 changed files with 7 additions and 11 deletions
18
main.py
18
main.py
|
@ -28,12 +28,13 @@ class Listener(StreamListener):
|
||||||
if seniority(status._json["created_at"]):
|
if seniority(status._json["created_at"]):
|
||||||
tweetText = sub(r'https?:\/\/\S+| +?\?|\?| +?\!| ?\!', '', status._json["text"])
|
tweetText = sub(r'https?:\/\/\S+| +?\?|\?| +?\!| ?\!', '', status._json["text"])
|
||||||
if tweetText.endswith(tuple(quoi)):
|
if tweetText.endswith(tuple(quoi)):
|
||||||
if status._json["user"]["screen_name"] in friends:
|
if status._json["user"]["id"] in friends:
|
||||||
try:
|
try:
|
||||||
self.api.update_status(status = choice(feur), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
self.api.update_status(status = choice(feur), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
||||||
print(f"{status._json['user']['screen_name']} est passé au coiffeur !")
|
print(f"{status._json['user']['screen_name']} est passé au coiffeur !")
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(f"Error happens! {error}")
|
print(f"Error happens! {error}")
|
||||||
|
pass
|
||||||
|
|
||||||
def seniority(date: str):
|
def seniority(date: str):
|
||||||
datetimeObject = datetime.strptime(date, '%a %b %d %H:%M:%S +0000 %Y') # Convert String format to datetime format
|
datetimeObject = datetime.strptime(date, '%a %b %d %H:%M:%S +0000 %Y') # Convert String format to datetime format
|
||||||
|
@ -42,7 +43,7 @@ def seniority(date: str):
|
||||||
return False if age.days >= 1 else True # False if older than a day
|
return False if age.days >= 1 else True # False if older than a day
|
||||||
|
|
||||||
def permute(array: list):
|
def permute(array: list):
|
||||||
quoi = []
|
quoiListe = []
|
||||||
|
|
||||||
for text in array: # all element of the list
|
for text in array: # all element of the list
|
||||||
n = len(text)
|
n = len(text)
|
||||||
|
@ -58,8 +59,8 @@ def permute(array: list):
|
||||||
temp = ""
|
temp = ""
|
||||||
for i in combination:
|
for i in combination:
|
||||||
temp += i
|
temp += i
|
||||||
quoi.append(temp)
|
quoiListe.append(temp)
|
||||||
return quoi
|
return quoiListe
|
||||||
|
|
||||||
def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user):
|
def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user):
|
||||||
"""Main method."""
|
"""Main method."""
|
||||||
|
@ -72,14 +73,10 @@ def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user):
|
||||||
stream = Stream(auth = api.auth, listener = listener)
|
stream = Stream(auth = api.auth, listener = listener)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
countOfFriends = api.get_user(user)._json["friends_count"]
|
listOfFriendsID = api.friends_ids(user)
|
||||||
friendsFromAPI = api.friends(user, skip_status = True, count = countOfFriends)
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(f"Une erreur est survenue, réessayez plus tard ({error})")
|
print(f"Une erreur est survenue, réessayez plus tard ({error})")
|
||||||
exit(1)
|
exit(1)
|
||||||
for friend in friendsFromAPI:
|
|
||||||
friends.append(friend._json["screen_name"])
|
|
||||||
print(f"Liste des comptes snipé ({len(friends)}): {', '.join(friends)}")
|
|
||||||
|
|
||||||
print(f"Scroll sur Twitter avec les abonnements de @{user}...")
|
print(f"Scroll sur Twitter avec les abonnements de @{user}...")
|
||||||
stream.filter(track = quoi, languages = ["fr"], is_async = True)
|
stream.filter(track = quoi, languages = ["fr"], is_async = True)
|
||||||
|
@ -94,8 +91,7 @@ if __name__ == '__main__':
|
||||||
PSEUDO is the PSEUDO of the account you want to listen to snipe.
|
PSEUDO is the PSEUDO of the account you want to listen to snipe.
|
||||||
"""
|
"""
|
||||||
quoi = permute(["quoi", "koi"])
|
quoi = permute(["quoi", "koi"])
|
||||||
quoi.append("https://twitter.com/shukuzi62/status/1422611919538724868/video/1")
|
feur = ["feur", "(feur)", "FEUR", "feur lol", "https://twitter.com/shukuzi62/status/1422611919538724868/video/1"]
|
||||||
feur = ["feur", "(feur)", "FEUR", "feur lol"]
|
|
||||||
friends = []
|
friends = []
|
||||||
keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDO"])
|
keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDO"])
|
||||||
main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDO"])
|
main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDO"])
|
||||||
|
|
Reference in a new issue