Skip to content

Commit

Permalink
Merge branch 'master' of github.com:olivierthereaux/oldtweets
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Thereaux committed Mar 1, 2020
2 parents b58d409 + 39018cc commit ff64bf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.mdown
Expand Up @@ -17,13 +17,13 @@ a credentials file is distributed with this script, as a sample. This file won't

Older versions had plenty of options. The latest version simplifies it greatly.

* dry-run to see all tweets older than 4 weeks
* see all tweets older than 4 weeks

cat credentials | ./oldtweets.py --dry-run
cat credentials | ./oldtweets.py

* print *and delete from twitter* tweets older than 4 weeks (your oldest tweets will be at the top)

cat credentials | ./oldtweets.py >> mytweetsbackupfile.txt
cat credentials | ./oldtweets.py --delete >> mytweetsbackupfile.txt

* [Bug] The tweets can still sometimes output in the wrong order, with some duplicates.

Expand All @@ -33,4 +33,4 @@ Older versions had plenty of options. The latest version simplifies it greatly.

Based on a script by David Larlet (@davidbgk)

Code, documentation and improvements contributed by Olivier Thereaux (@olivierthereaux), Karl Dubost (@karlpro), Florent Verschelde (@fvsch)
Code, documentation and improvements contributed by Olivier Thereaux (@olivierthereaux), Karl Dubost (@karlpro), Florent Verschelde (@fvsch), and Steve Frécinaux (@nud)
21 changes: 11 additions & 10 deletions oldtweets.py
Expand Up @@ -29,13 +29,13 @@
Based on a script by David Larlet @davidbgk
* dry-run to see all tweets older than 4 weeks
* see all tweets older than 4 weeks
cat credentials | ./oldtweets.py --dry-run
cat credentials | ./oldtweets.py
* print *and delete from twitter* tweets older than 4 weeks (your oldest tweets will be at the top)
cat credentials | ./oldtweets.py >> mytweetsbackupfile.txt
cat credentials | ./oldtweets.py --delete >> mytweetsbackupfile.txt
* [FIXME] The tweets can still sometimes output in the wrong order, with some duplicates.
Expand All @@ -51,21 +51,21 @@ def __init__(self, msg):


def main(argv=None):
option_delete = 1 #unless you use --dry-run, we're deleting
option_delete = False
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help", "dry-run"])
opts, args = getopt.getopt(argv[1:], "h", ["help", "delete"])
except getopt.error as msg:
raise Usage(msg)

# option processing
for option, value in opts:
if option in ("-h", "--help"):
raise Usage(help_message)
if option == "--dry-run":
option_delete = 0
if option == "--delete":
option_delete = True

except Usage as err:
print(sys.argv[0].split("/")[-1] + ": " + str(err.msg), file=sys.stderr)
Expand All @@ -91,7 +91,8 @@ def main(argv=None):
api = twitter.Api(consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token_key=access_token_key,
access_token_secret=access_token_secret)
access_token_secret=access_token_secret,
tweet_mode="extended")

statuses = list()
latest_tweet_id = None
Expand Down Expand Up @@ -131,10 +132,10 @@ def main(argv=None):
status_created_at = datetime.datetime.strptime(tweet.created_at, "%a %b %d %H:%M:%S +0000 %Y")
# [FIXME] Making sure not to delete new stuff, which for some odd reason seems to be necessary
if datetime.date(status_created_at.year, status_created_at.month, status_created_at.day) < fourweeksago:
tweet_text = str(tweet.text).replace('\n', '').replace('\r', '')
tweet_text = (tweet.full_text if hasattr(tweet, "full_text") else tweet.text).encode('utf-8').strip()
print("Tweet id: ", tweet.id, " -- Date: ", tweet.created_at, " || ", tweet_text)
# delete
if option_delete == 1:
if option_delete:
try:
status = api.DestroyStatus(tweet.id)
# wait a bit, throttled api.
Expand Down

0 comments on commit ff64bf3

Please sign in to comment.