Readit News logoReadit News
Posted by u/jamiehall 5 years ago
Ask HN: How would you improve this bash oneliner for deleting tweets?
Many people use tweet deletion services, which periodically remove everything from their Twitter timeline; I wondered if it could be done from a Bash command line.

I wrote up my experiences as an explainer for nontechnical people: https://jamiehall.cc/2020/03/10/delete-all-your-tweets-with-...

TL;DR, here is the oneliner I've been using:

  $ twurl "/1.1/statuses/user_timeline.json?screen_name=YOUR_TWITTER_HANDLE&count=200
    &max_id=$(
      twurl '/1.1/statuses/user_timeline.json?screen_name=YOUR_TWITTER_HANDLE&count=200&include_rts=1'
     | jq -c -r '.[] | .id_str' | head -10 | tail -1)
    &include_rts=1"
   | jq -c -r '.[] | .id_str' 
   | parallel -j 10 -a - twurl -X POST /1.1/statuses/destroy/{1}.json
   > /dev/null
[Edit: I've put line breaks in there to make it more legible.]

I'm curious if it's possible to do better. In particular: could this be more elegant? Is it possible to do it using common built-ins, instead of twurl and jq?

Any suggestions or improvements would be very welcome!

rhacker · 5 years ago
I feel like this is normally the content you see in Stack Overflow
ollien · 5 years ago
Probably best for the code review StackExchange forum, actually.
rococode · 5 years ago
Might be pretty fun for the code golf stack exchange too!
toomuchtodo · 5 years ago
You might consider putting this in a GitHub Gist, sharing the link for it, and accept comments and improvements within the Gist comments functionality.

This would also allow others to fork your code to improve upon or keep a copy for themselves.

jamiehall · 5 years ago
toomuchtodo · 5 years ago
Did you get the feedback you were looking for?
benburleson · 5 years ago
(Security risks aside,)

That can even allow people to curl and pipe to run in the terminal direct from github.

Deleted Comment

Pirate-of-SV · 5 years ago

    jq -c -r '.[] | .id_str'
    # Can be rewritten to
    jq -r '.[].id_str'

    jq -c -r '.[] | .id_str' | head -10 | tail -1
    # Can be rewritten to
    jq -r '.[9].id_str'

jamiehall · 5 years ago
Ah, nice. Thanks! :D
t0astbread · 5 years ago
What are the rate limits on the /statuses/destroy endpoint? I've checked the docs and the docs say it is limited but the actual limit is not specified.

Other than that, thanks for writing this! I've been thinking about a tool like this and this might come in handy. The code looks fine to me although I would probably spin this out into a script and add some logging, as others have already pointed out.

viraptor · 5 years ago
I don't think there's a good reason to calculate the max_id every time. If you want to delete all tweets, you could skip it.
a-wu · 5 years ago
I've tried this before in a Python script but quickly got rate limited by the 300 tweet update limit [0]. Does this get around that?

[0] https://developer.twitter.com/en/docs/basics/rate-limits

darepublic · 5 years ago
It's hard to imagine that it would
jamiehall · 5 years ago
Thank you to everybody who commented! The suggestions to use something more sensible than a oneliner (and to post on Stack instead) are well taken. A big motivation of this project was "just because", for shits and giggles, so I hope it's amused you for a minute or two. Cheers!
jlelse · 5 years ago
Not answering your question, but I found a way to mass delete tweets without creating an app: https://jlelse.blog/posts/mass-delete-tweets/