From 6e507187c9f8df8e0fa257a782841719cc1c4734 Mon Sep 17 00:00:00 2001 From: spla Date: Sun, 21 Aug 2022 20:03:01 +0200 Subject: [PATCH] deleted --- blocker.py | 121 ----------------------------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 blocker.py diff --git a/blocker.py b/blocker.py deleted file mode 100644 index 18ef5c6..0000000 --- a/blocker.py +++ /dev/null @@ -1,121 +0,0 @@ -import os -import sys -from mastodon import Mastodon -from mastodon.Mastodon import MastodonNotFoundError, MastodonNetworkError, MastodonReadTimeout, MastodonAPIError -import psycopg2 -import requests -import pdb - -def get_servers(software): - - servers_list = [] - - try: - - conn = None - - conn = psycopg2.connect(database = fediverse_db, user = fediverse_db_user, password = "", host = "/var/run/postgresql", port = "5432") - - cur = conn.cursor() - - cur.execute("select server from fediverse where software=(%s)", (software,)) - - rows = cur.fetchall() - - for row in rows: - - servers_list.append(row[0]) - - cur.close() - - return (servers_list) - - except (Exception, psycopg2.DatabaseError) as error: - - sys.exit(error) - - finally: - - if conn is not None: - - conn.close() - -def mastodon(): - - # Load secrets from secrets file - secrets_filepath = "secrets/secrets.txt" - uc_client_id = get_parameter("uc_client_id", secrets_filepath) - uc_client_secret = get_parameter("uc_client_secret", secrets_filepath) - uc_access_token = get_parameter("uc_access_token", secrets_filepath) - - # Load configuration from config file - config_filepath = "config/config.txt" - mastodon_hostname = get_parameter("mastodon_hostname", config_filepath) - - # Initialise Mastodon API - mastodon = Mastodon( - client_id = uc_client_id, - client_secret = uc_client_secret, - access_token = uc_access_token, - api_base_url = 'https://' + mastodon_hostname, - ) - - # Initialise access headers - headers={ 'Authorization': 'Bearer %s'%uc_access_token } - - return (mastodon, mastodon_hostname, headers) - -def db_config(): - - # Load db configuration from config file - config_filepath = "config/db_config.txt" - fediverse_db = get_parameter("fediverse_db", config_filepath) - fediverse_db_user = get_parameter("fediverse_db_user", config_filepath) - - return (fediverse_db, fediverse_db_user) - -def get_parameter( parameter, file_path ): - - if not os.path.isfile(file_path): - print("File %s not found, exiting."%file_path) - sys.exit(0) - - with open( file_path ) as f: - for line in f: - if line.startswith( parameter ): - return line.replace(parameter + ":", "").strip() - - print(file_path + " Missing parameter %s "%parameter) - - sys.exit(0) - -############################################################################### -# main - -if __name__ == '__main__': - - mastodon, mastodon_hostname, headers= mastodon() - - fediverse_db, fediverse_db_user = db_config() - - software = 'birdsitelive' - - servers_list = get_servers(software) - - pdb.set_trace() - for server in servers_list: - - print(f'blocking server {server}') - - #https://mastodont.cat/admin/domain_blocks/new?_domain=pawoo.net - data = { - 'domain': server - } - url = 'https://mastodont.cat/api/v1/domain_blocks' - - re_post = requests.post(url, headers=headers, data=data) - - print(f'status code: {re_post.status_code}') - - -