From f711671129d566be34f5b03857800ee986f060d0 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 3 Aug 2021 19:19:30 +0200 Subject: [PATCH] fix sending message to all twitter --- main.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 6d1c9f7..6c01399 100644 --- a/main.py +++ b/main.py @@ -2,8 +2,11 @@ from dotenv import load_dotenv from os import environ from tweepy import OAuthHandler, API, StreamListener, Stream from re import sub +from random import choice quoi = ["quoi", "koi"] +feur = ["feur", "(feur)", "FEUR", "feur lol"] +friends = [] def load(variables): """Load env variables.""" @@ -28,11 +31,14 @@ class Listener(StreamListener): tweetText = sub(r' ?\?| ?\!', '', status._json["text"]) if tweetText.endswith(tuple(quoi)): try: - self.api.update_status(status = 'feur', in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True) - except: + if status._json["user"]["screen_name"] in friends: + 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 !") + except Exception as error: + print(error) pass -def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, userID): +def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user): """Main method.""" auth = OAuthHandler(consumerKey, consumerSecret) auth.set_access_token(accessToken, accessTokenSecret) @@ -40,19 +46,22 @@ def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, userID): api = API(auth) listener = Listener(api) - stream = Stream(api.auth, listener) - user = api.get_user(userID) - print(f"Scroll sur Twitter avec les abonnés de @{user.screen_name}...") - stream.filter(follow=[userID], track=quoi, is_async = True) + stream = Stream(auth = api.auth, listener = listener) + + for friend in api.friends(user, skip_status = True): + friends.append(friend._json["screen_name"]) + + print(f"Scroll sur Twitter avec les abonnés de @{user}...") + stream.filter(track = quoi, languages=["fr"], is_async = True) if __name__ == '__main__': """ - TOKEN is the Access Token available in the Authentication Tokens section under Access Token and Secret sub-heading - TOKEN_SECRET is the Access Token Secret available in the Authentication Tokens section under Access Token and Secret sub-heading - CONSUMER_KEY is the API Key available in the Consumer Keys section - CONSUMER_SECRET is the API Secret Key available in the Consumer Keys section + TOKEN is the Access Token available in the Authentication Tokens section under Access Token and Secret sub-heading. + TOKEN_SECRET is the Access Token Secret available in the Authentication Tokens section under Access Token and Secret sub-heading. + CONSUMER_KEY is the API Key available in the Consumer Keys section. + CONSUMER_SECRET is the API Secret Key available in the Consumer Keys section. -- - ID is the ID of the account you want to listen to. The ID is fetchable with this website: https://commentpicker.com/twitter-id.php or others + PSEUDO is the PSEUDO of the account you want to listen to snipe. A proportion of who s.he follow will be targeted. """ - keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "ID"]) - main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["ID"]) + keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDO"]) + main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDO"])