Skip to content

Instantly share code, notes, and snippets.

@undergroundmonorail
Created January 12, 2020 02:40
Show Gist options
  • Save undergroundmonorail/3a4303a2a5fe0705a79e1c4967495a45 to your computer and use it in GitHub Desktop.
Save undergroundmonorail/3a4303a2a5fe0705a79e1c4967495a45 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from mastodon import Mastodon
import psycopg2
mastodon = Mastodon(access_token='automatic-tooter_usercred.secret', api_base_url='https://glaceon.social')
with psycopg2.connect('dbname=mastodon_production user=mastodon') as conn:
with conn.cursor() as cursor:
cursor.execute("""
SELECT l.username, STRING_AGG(r.username, ',')
FROM follows
JOIN accounts l ON l.id=follows.account_id
JOIN accounts r ON r.id=follows.target_account_id
WHERE r.domain LIKE 'witches.live'
AND l.domain IS NULL
GROUP BY l.username;
""")
for local, remote in cursor.fetchall():
message = ('Hello, @{}. You are receiving this automated message because you follow at least one user from https://witches.live.\n\n'
'This is a heads up that, soon, this instance will be defederating from them. This has been a long time coming. '
'The original decision was to keep them silenced because the instance wasn\'t "obviously bad", wanting to protect users who were unaware of the admin\'s behaviour. '
'For better or for worse, the amount of drama that has happened surrounding w.l has made this unecessary. '
'At this point, their users are likely either aware of the issues with the instance or remaining willfully ignorant.\n\n'
'You are being given time to reach out to anyone you know on that instance who you wish to maintain ties with, either to establish another contact method or '
'to urge them to find a new instance. The suspension will occur on Monday (EST time).\n\n'
'The https://witches.live users you follow are:\n\n'
'{}\n\n'
'Please contact me at @\u200bmonorail to express any concerns, as I can\'t guarantee that any replies to this account will be read in a timely manner.\n\n'
'Thank you for your attention, and for being a part of https://glaceon.social!').format(local, '\n'.join(['- @\u200b{}@witches.live'.format(r) for r in remote.split(',')]))
mastodon.status_post(message, visibility='direct')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment