more logging

This commit is contained in:
Karol Wypchlo 2021-03-01 17:08:10 +01:00
parent ac5dc3eca7
commit b0d49e2f2f
1 changed files with 7 additions and 2 deletions

View File

@ -10,22 +10,27 @@ bot_token = setup()
client = discord.Client() client = discord.Client()
async def block_skylinks_from_airtable(): async def block_skylinks_from_airtable():
print("Pulling blocked skylinks from airtable via api integration")
headers = { "Authorization": "Bearer " + AIRTABLE_API_KEY } headers = { "Authorization": "Bearer " + AIRTABLE_API_KEY }
airtable = requests.get( airtable = requests.get(
"https://api.airtable.com/v0/" + AIRTABLE_TABLE + "/Table%201?fields%5B%5D=" + AIRTABLE_FIELD, headers=headers "https://api.airtable.com/v0/" + AIRTABLE_TABLE + "/Table%201?fields%5B%5D=" + AIRTABLE_FIELD, headers=headers
).json() ).json()
skylinks = [entry['fields'][AIRTABLE_FIELD] for entry in airtable['records']] 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() 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() 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' } headers = { 'user-agent': 'Sia-Agent' }
auth = ('', apipassword) auth = ('', apipassword)
data = json.dumps({ 'add': skylinks }) data = json.dumps({ 'add': skylinks })
response = requests.post('http://' + ipaddress + ':9980/skynet/blocklist', auth = auth, headers = headers, data = data) response = requests.post('http://' + ipaddress + ':9980/skynet/blocklist', auth = auth, headers = headers, data = data)
if response.status_code != 204: if response.status_code == 204:
message = "Blocklist responded with code " + str(response.status_code) + ": " + (response.text or "empty response") 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) await send_msg(client, message, force_notify=True)
async def exit_after(delay): async def exit_after(delay):