From fea2ed5d510d6d5d9f3afaaa34474be9ef0ddc64 Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 5 Sep 2024 15:23:33 -0700 Subject: [PATCH] Basic scripst for updating neocities stuff --- scripts/compare.py | 7 +++++++ scripts/neocities.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 scripts/compare.py create mode 100644 scripts/neocities.py diff --git a/scripts/compare.py b/scripts/compare.py new file mode 100644 index 0000000..28d7764 --- /dev/null +++ b/scripts/compare.py @@ -0,0 +1,7 @@ +import hashlib + +with open('public/tags/index.xml') as file: + data = hashlib.sha1(file.read().encode('utf-8')) + +remote = '99d66a9e171feaf11be88b831bc69c55d85c1b4b' +print(remote == data.hexdigest()) diff --git a/scripts/neocities.py b/scripts/neocities.py new file mode 100644 index 0000000..150f2e0 --- /dev/null +++ b/scripts/neocities.py @@ -0,0 +1,29 @@ +from os import environ +from requests import get +from json import dumps + +def request(key: str, uri: str): + url = f'https://neocities.org{uri}' + headers = { 'Authorization': f'Bearer {key}' } + response = get(url, headers=headers) + return response.json() + +def get_new_content(key: str): + ''' + Fetches a list of all files on neocities + ''' + # First fetch the hashes of all our files + response = request(key, '/api/list') + remote_files = response['files'] + + # COmpare remote hashes to local hashes + + +if __name__ == '__main__': + key = environ.get('NEOCITIES_API_KEY') + if key is None: + print('Check to ensure NEOCITIES_API_KEY is set in the env vars') + exit(1) + else: + get_public_contents(key) +