fix error in dict and add exception

This commit is contained in:
Antonio J. Delgado 2024-01-23 20:51:17 +02:00
parent c1c431cf12
commit 103c8a6605

View file

@ -12,7 +12,6 @@ from logging.handlers import SysLogHandler
import sqlite3
import time
import re
import json
import click
import click_config_file
import requests
@ -83,7 +82,7 @@ class DiscoverMastodonServers:
self._log.debug(
"Server '%s' didn't return Content-Type header. Headers: '%s'. Content returned: '%s'",
server['name'],
json.dumps(result.headers, indent=2),
result.headers,
result.content
)
else:
@ -119,6 +118,14 @@ class DiscoverMastodonServers:
server['name'],
error
)
except Exception as error:
server['state'] = 'Error'
self._log.warning(
"Error fetching endpoint '%s' from server '%s'. %s",
endpoint,
server['name'],
error
)
return data
def get_instance_info(self, server):
@ -189,7 +196,7 @@ class DiscoverMastodonServers:
}
)
else:
server[1]['peers'] = False
server['peers'] = False
self._log.debug("Fetching public timeline in server '%s'", server_name)
data = self.get_timeline(server)
if data:
@ -233,6 +240,8 @@ class DiscoverMastodonServers:
record['peers'] = True
if 'timeline' not in record:
record['timeline'] = True
if 'last_update' not in record:
record['last_update'] = time.time()
cur = self.conn.cursor()
result_select = cur.execute(f"""
SELECT name FROM {table} WHERE name = '{record['name']}'