Created
March 5, 2018 15:22
-
-
Save Muratam/321bc4ad7f08d3a4fcd3c77246326ee8 to your computer and use it in GitHub Desktop.
twitter消すやつ
This file contains 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
import pandas as pd | |
import tweepy | |
def get_api(): | |
c_k = "K**" | |
c_s = "u**" | |
a_k = "2**" | |
a_s = "b**" | |
auth = tweepy.OAuthHandler(c_k, c_s) | |
auth.set_access_token(a_k, a_s) | |
api = tweepy.API(auth) | |
return api | |
def destroy_memory(df): | |
api = get_api() | |
for i,r in df.iterrows(): | |
tweet_id = r["tweet_id"] | |
text = r["text"] | |
urls = r["expanded_urls"] | |
with_media = False | |
if type(urls) is str: | |
urls = urls.split(",") | |
for url in urls: | |
if not ("photo" in url): | |
continue | |
with_media = True | |
break | |
try: | |
if text.startswith("RT"): | |
api.destroy_status(tweet_id) | |
api.unretweet(tweet_id) | |
elif not with_media: | |
if not ("@" in text) : continue | |
if not ("http" in text) : continue | |
api.destroy_status(tweet_id) | |
except Exception as e: | |
print(e) | |
df = pd.read_csv("tweets.csv") | |
destroy_memory(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment