Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions deletetweets.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env python

import argparse
import csv
from backports import csv
import sys
import time
import os
import twitter
import io
from dateutil.parser import parse

__author__ = "Koen Rouwhorst"
__version__ = "0.1"
__version__ = "0.1.1"

def delete(api, date, r):
with open("tweets.csv") as file:
with io.open("tweets.csv", encoding='utf-8') as file:
count = 0

for row in csv.DictReader(file):
Expand All @@ -27,16 +28,16 @@ def delete(api, date, r):
continue

try:
print "Deleting tweet #{0} ({1})".format(tweet_id, tweet_date)
print("Deleting tweet #{0} ({1})".format(tweet_id, tweet_date))

api.DestroyStatus(tweet_id)
count += 1
time.sleep(0.5)

except twitter.TwitterError, err:
print "Exception: %s\n" % err.message
except twitter.TwitterError as err:
print("Exception: %s\n" % err.message)

print "Number of deleted tweets: %s\n" % count
print("Number of deleted tweets: %s\n" % count)

def error(msg, exit_code=1):
sys.stderr.write("Error: %s\n" % msg)
Expand All @@ -52,9 +53,9 @@ def main():
args = parser.parse_args()

if not ("TWITTER_CONSUMER_KEY" in os.environ and
"TWITTER_CONSUMER_SECRET" in os.environ and
"TWITTER_ACCESS_TOKEN" in os.environ and
"TWITTER_ACCESS_TOKEN_SECRET" in os.environ):
"TWITTER_CONSUMER_SECRET" in os.environ and
"TWITTER_ACCESS_TOKEN" in os.environ and
"TWITTER_ACCESS_TOKEN_SECRET" in os.environ):
error("No consumer key/secret and/or access token/secret set.")

api = twitter.Api(consumer_key=os.environ['TWITTER_CONSUMER_KEY'],
Expand All @@ -64,6 +65,5 @@ def main():

delete(api, args.date, args.restrict)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
python-twitter==3.4.2
python-dateutil==2.7.3
backports.csv==1.0.6