pagination

This commit is contained in:
Karol Wypchlo 2021-03-01 23:08:38 +01:00
parent 6af13b4715
commit 002ae6c6d8
1 changed files with 23 additions and 14 deletions

View File

@ -6,27 +6,36 @@ from bot_utils import setup, send_msg
bot_token = setup() bot_token = setup()
client = discord.Client() client = discord.Client()
AIRTABLE_TABLE = "app89plJvA9EqTJEc"
AIRTABLE_FIELD = "Link"
AIRTABLE_API_KEY = os.getenv('AIRTABLE_API_KEY') AIRTABLE_API_KEY = os.getenv('AIRTABLE_API_KEY')
AIRTABLE_TABLE = os.getenv('AIRTABLE_TABLE', 'app89plJvA9EqTJEc')
AIRTABLE_FIELD = os.getenv('AIRTABLE_FIELD', 'Link')
async def block_skylinks_from_airtable(): async def block_skylinks_from_airtable():
print("Pulling blocked skylinks from airtable via api integration") print("Pulling blocked skylinks from airtable via api integration")
headers = { "Authorization": "Bearer " + AIRTABLE_API_KEY } headers = { "Authorization": "Bearer " + AIRTABLE_API_KEY }
airtable = requests.get( skylinks = []
"https://api.airtable.com/v0/" + AIRTABLE_TABLE + "/Table%201?fields%5B%5D=" + AIRTABLE_FIELD, headers=headers offset = ''
) while len(skylinks) == 0 or offset:
query = '&'.join(['fields%5B%5D=' + AIRTABLE_FIELD, ('offset=' + offset) if offset else ''])
airtable = requests.get(
"https://api.airtable.com/v0/" + AIRTABLE_TABLE + "?" + query, headers=headers
)
if airtable.status_code != 200: if airtable.status_code != 200:
message = "Airtable blocklist integration responded with code " + str(airtable.status_code) + ": " + (airtable.text or "empty response") message = "Airtable blocklist integration responded with code " + str(airtable.status_code) + ": " + (airtable.text or "empty response")
return print(message) or await send_msg(client, message, force_notify=True) return print(message) or await send_msg(client, message, force_notify=True)
airtable_data = airtable.json()
skylinks = skylinks + [entry['fields'][AIRTABLE_FIELD] for entry in airtable_data['records']]
if len(skylinks) == 0:
return print("Airtable returned 0 skylinks - make sure your configuration is correct")
print(airtable_data.offset)
offset = airtable_data.offset
print(airtable_data.offset)
skylinks = [entry['fields'][AIRTABLE_FIELD] for entry in airtable.json()['records']] print("Airtable returned " + str(len(skylinks)) + " skylinks to block")
if len(skylinks) == 0:
return print("Airtable returned 0 skylinks to block - make sure your table configuration is correct")
else:
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()