Skip to content

Instantly share code, notes, and snippets.

@Muratam
Created March 5, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muratam/321bc4ad7f08d3a4fcd3c77246326ee8 to your computer and use it in GitHub Desktop.
Save Muratam/321bc4ad7f08d3a4fcd3c77246326ee8 to your computer and use it in GitHub Desktop.
twitter消すやつ
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