From 25ba6be97827598a4d2b686e136c8d22dc23a658 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 21 May 2024 19:41:59 +1200 Subject: [PATCH] remove code from test route --- app/main/routes.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/app/main/routes.py b/app/main/routes.py index c091c018..4e805eb8 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -321,43 +321,6 @@ def list_files(directory): @bp.route('/test') def test(): - # Check for dormant or dead instances - instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all() - HEADERS = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'} - for instance in instances: - try: - nodeinfo = requests.get(f"https://{instance.domain}/.well-known/nodeinfo", headers=HEADERS, - timeout=5, allow_redirects=True) - - if nodeinfo.status_code == 200: - nodeinfo_json = nodeinfo.json() - for links in nodeinfo_json['links']: - if 'rel' in links and (links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0' or - links['rel'] == 'https://nodeinfo.diaspora.software/ns/schema/2.0'): - try: - sleep(0.1) - node = requests.get(links['href'], headers=HEADERS, timeout=5, allow_redirects=True) - if node.status_code == 200: - node_json = node.json() - if 'software' in node_json: - instance.software = node_json['software']['name'] - instance.version = node_json['software']['version'] - instance.failures = 0 - instance.dormant = False - elif node.status_code >= 400: - instance.failures += 1 - except: - instance.failures += 1 - elif nodeinfo.status_code >= 400: - instance.failures += 1 - except: - instance.failures += 1 - if instance.failures > 7 and instance.dormant == True: - instance.gone_forever = True - elif instance.failures > 2 and instance.dormant == False: - instance.dormant = True - db.session.commit() - return 'done'