A program that uses Tweepy in Python to monitor the timeline and output only deleted tweets as standard output.
-Twitter agrees to revive the tweet archive site "Politwoops" deleted by politicians -Politwoops (Archive site for tweets deleted by politicians)
I'm using Tweepy with Python3. You can install it by doing `` `pip install tweepy```. Please enter the one you prepared for CONSUMER_KEY.
delcheck.py
# coding: UTF-8
import tweepy
from datetime import timedelta
import json
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
my_db = {}
def get_oauth():
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
return auth
def pprint(dict_data):
for k, v in dict_data.items():
print(k, v)
class Listener(tweepy.StreamListener):
def on_error(self, status_code):
print("Error: " + str(status_code))
def on_data(self, data):
obj = json.loads(data, encoding="UTF-8")
if "delete" in obj:
tweet_id = obj.get("delete").get("status").get("id")
print("deleted!")
if tweet_id in my_db:
print(my_db[tweet_id])
else:
print("-")
elif "text" in obj:
my_db[obj.get("id")] = obj.get("user").get("screen_name") + ": " + obj.get("text")
def on_timeout(self):
print("Timeout...")
if __name__ == "__main__":
auth = get_oauth()
listener = Listener()
stream = tweepy.Stream(auth, listener)
stream.userstream()
Notifications such as deletion will be sent to on_data. The data of the user's timeline is saved from the time of startup, and if there is something saved in the deleted one, it will be output as standard. Using a proper DB Instead, I save the data from the timeline (tweet body only) in my_db (dictionary type object).
What I noticed after moving it for a day was that everyone deleted the tweets.
A service like this violates Twitter's terms. Note that a similar service has been angry and erased from Twitter.
Follow us: alien: @redshoga
Recommended Posts