Created
January 27, 2020 10:39
-
-
Save OldBigBuddha/7c1a02af9b50b5027f5b6d86285e772e to your computer and use it in GitHub Desktop.
Tweet を全削除するスクリプト、tweepy 3.6.0 が必要
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ref: https://kurozumi.github.io/tweepy/index.html | |
| import tweepy | |
| consumer_key = <YOUR KEY> | |
| consumer_secret = <YOUR SERCRET> | |
| auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
| # ref: https://kurozumi.github.io/tweepy/auth_tutorial.html | |
| try: | |
| redirect_url = auth.get_authorization_url() | |
| print(redirect_url) | |
| verifier_pin = input('PIN:') | |
| auth.get_access_token(verifier=verifier_pin) | |
| print(auth.access_token) | |
| print(auth.access_token_secret) | |
| except tweepy.TweepError: | |
| print('Error! Failed to get request token.') | |
| auth.set_access_token(auth.access_token, auth.access_token_secret) | |
| api = tweepy.API(auth) | |
| # ref:https://kurozumi.github.io/tweepy/code_snippet.html#handling-the-rate-limit-using-cursors | |
| def limit_handled(cursor): | |
| while True: | |
| try: | |
| yield cursor.next() | |
| except tweepy.RateLimitError: | |
| print('Take a break', 15*60, 'sec.') | |
| time.sleep(15 * 60) | |
| for tweet in limit_handled( tweepy.Cursor(api.user_timeline).items()): | |
| api.destroy_status(tweet.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment