Created
October 29, 2015 15:54
-
-
Save utgwkk/aaf188c3046be44e58c0 to your computer and use it in GitHub Desktop.
"(いま|今)のなしで?" で前のツイートを削除できるぞ!!!!!
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
#!/usr/bin/python3 | |
import re | |
import tweepy | |
from tokens import * | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
api = tweepy.API(auth) | |
me = api.me().screen_name | |
def is_target(s): | |
return not re.search(r'(いま|今)のなしで?', s.text) is None | |
class MyStream(tweepy.StreamListener): | |
def __init__(self): | |
super(MyStream, self).__init__() | |
self.target = None | |
def on_status(self, status): | |
if status.user.screen_name == me: | |
if is_target(status) and self.target is not None: | |
try: | |
api.destroy_status(self.target) | |
except tweepy.TweepError: | |
pass | |
else: | |
try: | |
api.destroy_status(status.id) | |
except tweepy.TweepError: | |
pass | |
else: | |
print(self.target, "と", status.id, "が消されたよ") | |
self.target = None | |
else: | |
self.target = status.id | |
print(status.id, status.text) | |
if __name__ == '__main__': | |
stream = tweepy.Stream(auth, MyStream()) | |
stream.userstream() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment