Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Last active December 29, 2015 03:48
Show Gist options
  • Save utgwkk/7609952 to your computer and use it in GitHub Desktop.
Save utgwkk/7609952 to your computer and use it in GitHub Desktop.
tweets.csv を基にNGワードを含む過去ツイート(RT)を削除してすっきりトゥイッターライフを送ろう(for Python, requires tweepy)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
import csv
import tweepy
CONSUMER_KEY = 'CONSUMER_KEY'
CONSUMER_SECRET = 'CONSUMER_SECRET'
ACCESS_KEY = 'ACCESS_TOKEN'
ACCESS_SECRET = 'ACCESS TOKEN SECRET'
csv_path = 'tweets.csv' # tweets.csvのパス
ngwords = ('ここにNGワードを書き連ねよう')
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
cnt = 0
reader = csv.reader(open(csv_path,'rb'))
for row in reader:
if row[0] == 'tweet_id': continue
for ng in ngwords:
if ng in row[7]:
#print unicode(row[7],encoding='utf-8')
try:
api.destroy_status(int(row[0]))
except tweepy.error.TweepError:
pass
else:
cnt += 1
finally:
break
print '%d件削除しました'%cnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment