From b0d49e2f2f10d23d51c66a12c1d345c3f117c846 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Mon, 1 Mar 2021 17:08:10 +0100 Subject: [PATCH] more logging --- setup-scripts/blocklist-airtable.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup-scripts/blocklist-airtable.py b/setup-scripts/blocklist-airtable.py index e5b352fc..4657b22d 100755 --- a/setup-scripts/blocklist-airtable.py +++ b/setup-scripts/blocklist-airtable.py @@ -10,22 +10,27 @@ bot_token = setup() client = discord.Client() async def block_skylinks_from_airtable(): + print("Pulling blocked skylinks from airtable via api integration") headers = { "Authorization": "Bearer " + AIRTABLE_API_KEY } airtable = requests.get( "https://api.airtable.com/v0/" + AIRTABLE_TABLE + "/Table%201?fields%5B%5D=" + AIRTABLE_FIELD, headers=headers ).json() skylinks = [entry['fields'][AIRTABLE_FIELD] for entry in airtable['records']] + print("Airtable returned " + str(len(skylinks)) + " skylinks to block") apipassword = os.popen('docker exec sia cat /sia-data/apipassword').read().strip() ipaddress = os.popen('docker inspect -f \'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}\' sia').read().strip() + print("Sending blocklist request to siad") headers = { 'user-agent': 'Sia-Agent' } auth = ('', apipassword) data = json.dumps({ 'add': skylinks }) response = requests.post('http://' + ipaddress + ':9980/skynet/blocklist', auth = auth, headers = headers, data = data) - if response.status_code != 204: - message = "Blocklist responded with code " + str(response.status_code) + ": " + (response.text or "empty response") + if response.status_code == 204: + print("Skylinks successfully added to siad blocklist") + else: + message = "Siad blocklist endpoint responded with code " + str(response.status_code) + ": " + (response.text or "empty response") await send_msg(client, message, force_notify=True) async def exit_after(delay):