This code allows you to delete your tweets both and Twitter and Mastodon depending on various criterias.
I use it to delete most tweets after 10 days, with additionnal complexe rules (keep tweets I favorited, keep private messages, keep tweet with high interactions, …)
Contributions are more than welcomed. Feel free to use and adapt. Ask questions if you have any. Please do contact me to let me know how your are using it.
After checking out the repo, run bin/setup
to install dependencies.
To install this gem onto your local machine, run bundle exec rake install
.
Twitter: Create a script that uses TweetDeletion. You will need a Twitter Development account and to create an application on the App Deshboard. You should have a consumer_key and a consumer_secret for the app, and an access_token and an access_token_secret per authorized account. If you already have an ap registered and try to authorize other accounts, Twitter.authorize_request
and Twitter.get_token
will help you manage that.
Mastodon: First register your app to have a client_id and client_secret, then use them to get a bearer_token per authorized account with your email and password. You will find some code on Mastodon.register_and_get_token
to help you.
Create a script then execute it with bundle exec your_script.rb
.
Exemple of scripts are below:
require "tweet_deletion"
accounts = [
{
network: "twitter",
consumer_key: "xxx",
consumer_secret: "xxx",
access_token: "xxx",
access_token_secret: "xxx"
},
{
network: "mastodon",
instance: "your instance url",
bearer_token: "xxx"
}
]
TweetDeletion.with( accounts ) do
for_favorites do
keep_if by(:me)
keep_if earlier_than( 10.days.ago )
keep_if rt_by(:me)
end
for_tweets(include_rts: true) do
keep_if earlier_than( 10.days.ago )
delete_if rt_of(:me) if is_rt
keep_if fav_by(:me)
keep_if has_kept_reply
keep_if has_kept_quote
keep_if is_direct_message
unless is_rt
keep_if rt_by_more_than( 50 )
keep_if fav_by_more_than( 50 )
end
end
end
Or with emojis as visual feedback (optional):
require "tweet_deletion"
accounts = [
{
network: "twitter",
consumer_key: "xxx",
consumer_secret: "xxx",
access_token: "xxx",
access_token_secret: "xxx"
},
{
network: "mastodon",
instance: "your instance url",
bearer_token: "xxx"
}
]
TweetDeletion.with( accounts ) do
for_favorites do
keep_if by(:me), tag:" 🗣 "
keep_if earlier_than( 12.days.ago ), tag:" 📅 "
keep_if rt_by(:me), tag:" 💬 "
else_delete tag:" 🗑 "
end
for_tweets(include_rts: true) do
keep_if earlier_than( 10.days.ago ), tag:" 📅 "
delete_if (is_rt and rt_of(:me)), tag:" 🗑 "
keep_if fav_by(:me), tag: " ❤ ️"
keep_if has_kept_reply, tag:" 💬 "
keep_if has_kept_quote, tag:" 💬 "
keep_if is_direct_message, tag: " 📩 "
unless is_rt
keep_if rt_by_more_than( 15 ), tag: " 💯 "
keep_if fav_by_more_than( 15 ), tag: " 💯 "
end
else_delete tag:" 🗑 "
end
end
Download your Twitter Archive and unzip it to pass the folder's path to a specific set of rules into your script:
for_archive("./archive/") do
keep_if earlier_than( 10.days.ago ), tag:" 📅 "
delete_if (is_rt and rt_of(:me)), tag:" 🗑 "
keep_if fav_by(:me), tag: " ❤ ️"
keep_if has_kept_reply, tag:" 💬 "
keep_if has_kept_quote, tag:" 💬 "
unless is_rt
keep_if rt_by_more_than( 15 ), tag: " 💯 "
keep_if fav_by_more_than( 15 ), tag: " 💯 "
end
else_delete tag:" 🗑 "
end
Then execute you script:
Inside the for_*
blocks, you can use actions and conditions
The first action to match will be used.
else_keep
keep your tweetelse_delete
delete your tweetkeep_if
keep your tweet if the parameter evaluates totrue
delete_if
delete your tweet if the parameter evaluates totrue
keep_unless
keep your tweet unless the parameter evaluates totrue
delete_unless
delete your tweet unless the parameter evaluates totrue
The optionnal tag
named argument will display the corresponding tag in the console when the action is applied.
me
will return the current account name (without the leading "@")tweet
will return an instance ofStatus
with your tweetmastodon
andtwitter
will return the currentMastodon
orTwitter
client instance
by(user)
will match if the tweet is written by the given userearlier_than(date)
will match if the tweet has been written after the given dateolder_than(date)
will match if the tweet has been written before the given datert_by(:me)
will match if you retweeted the tweetfav_by(:me)
will match if you favorited the tweetis_rt
will match if the tweet is a retweetlinks_to(url)
will match if the link (as a string) is present in the tweet (regexp are also allowed)contains(match)
will match if the tweet contains the given string (regexp are also allowed)rt_of(who)
will match if the original tweet was written by the given useron_mastodon
andon_twitter
will match is the current account is on the corresponding plateformis_public
,is_private
,is_unlisted
,is_direct_message
will match depending on the tweet visibilityhas_media
will match if the tweet has an embedded image or mediahas_kept_quote
will match if you decided to keep a message of yours which quote this tweethas_kept_reply
will match if you decided to keep a message of yours which directly reply to this tweet. It will not follow indirect chains of tweets, if you reply to someone else's tweet which itself replies to a tweet you decided to keep: this will not match. However, if you consitently keep each message which has a reply from you, this rule will help you keep alive a whole thread provided you manage to keep the last one of the thread.
Users are expected in numeric (integer ids) or string (without the leading "@" but with the instance name on Mastodon). The magic value :me
will match the current user.
For Twitter, a tweet is marked as private if the author account is protected, public otherwise.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at TweetDeletion.
The gem is available as open source under the terms of the MIT License.