Basic scripst for updating neocities stuff
This commit is contained in:
parent
b96391d813
commit
fea2ed5d51
7
scripts/compare.py
Normal file
7
scripts/compare.py
Normal file
@ -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())
|
29
scripts/neocities.py
Normal file
29
scripts/neocities.py
Normal file
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user