Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Created Oct 29, 2015
Embed
What would you like to do?
"(いま|今)のなしで?" で前のツイートを削除できるぞ!!!!!
#!/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