From c1d1c976982e652a0ce26fd4d618fd1ee6fabb6a Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Mon, 19 Jun 2023 03:33:15 +0300 Subject: [PATCH] Fetch new instances from api.fediverse.observer --- src/settings.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/settings.py b/src/settings.py index d531b1c..b06d447 100644 --- a/src/settings.py +++ b/src/settings.py @@ -128,6 +128,29 @@ def get_new_funkwhale_servers(): for i in new_instances_list: if i[0] not in exists_instances and i[1]: new_instances.append(i[0]) + new_instances.extend(get_new_funkwhale_servers_fediverse_observer()) + new_instances = list(dict.fromkeys(new_instances)) return new_instances except: # If any errors then return empty list return [] + + +def get_new_funkwhale_servers_fediverse_observer(): + try: + graphQL_request = { + 'query': + '{\n nodes(softwarename: \"funkwhale\") {\n domain\n metanodeinfo\n }\n}' + } + r = requests.post('https://api.fediverse.observer/', + headers={'Accept-Encoding': 'gzip, deflate'}, + json=graphQL_request) + new_instances = [] + exists_instances = get_config('public_list_instances') + for i in r.json()['data']['nodes']: + if i.get('metanodeinfo'): + auth_no_required = json.loads(i['metanodeinfo'])['library']['anonymousCanListen'] + if auth_no_required and i['domain'] not in exists_instances: + new_instances.append(i['domain']) + return new_instances + except: + return []