diff --git a/Scripts/kemono.party/kemono.party-creator-siblings.py b/Scripts/kemono.party/kemono.party-creator-siblings.py index 374f2ade..9e13d006 100644 --- a/Scripts/kemono.party/kemono.party-creator-siblings.py +++ b/Scripts/kemono.party/kemono.party-creator-siblings.py @@ -1,14 +1,27 @@ -import requests, json, os +import requests, json, os, sys -creators = json.loads(requests.get('https://kemono.party/api/creators').text) -file = open("kemono.party_siblings.txt", 'a',encoding="utf-8") +API_URL = 'https://kemono.party/api/v1/creators' +OUT_FILE = 'kemono.party_siblings.txt' -for creator in creators: - name = creator['name'] - id = creator['id'] - service = creator["service"] - if name and id != "": - if service == "fanbox": continue - file.write(service + " id:" + id + "\ncreator:" + name.replace('\n', ' ') + "\n") +def get_creators(): + creators = None + try: + creators = json.loads(requests.get(API_URL).text) + except Exception as exc: + with sys.stderr as dest: + print(exc, file=dest) + print(f'Error fetching creators. Ensure URL "{API_URL}" is correct.') + return creators + +creators = get_creators() +if creators is None: exit(1) +with open(OUT_FILE, 'a', encoding='utf-8') as file: + for creator in creators: + name = creator['name'] + id = creator['id'] + service = creator['service'] + if name and id: + if service == "fanbox": continue + creator_name = name.replace('\n', ' ') + file.write(f'{service} id:{id}\ncreator:{creator_name}\n') -file.close() \ No newline at end of file