continue
logger.debug("Fetched %d Bytes, parsing CSV ...", len(response.content))
- reader = csv.DictReader(response.content.decode('utf-8').splitlines(), dialect="unix")
+ reader = csv.DictReader(response.content.decode("utf-8").splitlines(), dialect="unix")
blockdict = list()
locking.acquire()
- logger.info("Fetching url='%s' from fedilist.com ...", url)
+ logger.info("Fetching url='%s' ...", url)
response = reqto.get(
url,
headers=network.web_headers,
)
logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
- reader = csv.DictReader(response.content.decode('utf-8').splitlines(), dialect="unix")
+ if not response.ok or response.status_code >= 300 or len(response.content) == 0:
+ logger.warning("Failed fetching url='%s': response.ok='%s',response.status_code=%d,response.content()=%d - EXIT!", response.ok, response.status_code, len(response.text))
+ return 1
+
+ reader = csv.DictReader(response.content.decode("utf-8").splitlines(), dialect="unix")
logger.debug("reader[]='%s'", type(reader))
blockdict = list()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
+def fetch (api_domain: str) -> dict:
+ logger.debug("api_domain='%s' - CALLED!", api_domain)
+ domain_helper.raise_on(api_domain)
+
+ database.cursor.execute("SELECT * FROM apis WHERE api_domain = ? LIMIT 1", [api_domain])
+
+ row = database.cursor.fetchone()
+ logger.debug("row[]='%s' - EXIT!", type(row))
+ return row
+
def is_recent(api_domain: str) -> bool:
logger.debug("api_domain='%s' - CALLED!", api_domain)
domain_helper.raise_on(api_domain)
is_recent = False
- database.cursor.execute("SELECT last_accessed FROM apis WHERE hostname = ? LIMIT 1", [api_domain])
- row = database.cursor.fetchone()
+ row = fetch(api_domain)
logger.debug("row[]='%s'", type(row))
if row is not None:
logger.debug("api_domain='%s',row[last_accessed]=%d", api_domain, row["last_accessed"])
logger.debug("api_domain='%s' - CALLED!", api_domain)
domain_helper.raise_on(api_domain)
- database.cursor.execute("SELECT * FROM apis WHERE hostname = ? LIMIT 1", [api_domain])
-
- row = database.cursor.fetchone()
+ row = fetch(api_domain)
logger.debug("row[]='%s'", type(row))
if row is None:
# Add instance
- database.cursor.execute("INSERT INTO apis (hostname, last_accessed) VALUES (?, ?)", [
+ database.cursor.execute("INSERT INTO apis (api_domain, last_accessed) VALUES (?, ?)", [
api_domain,
time.time()
])
else:
# Update last_accessed
- database.cursor.execute("UPDATE apis SET last_accessed = ? WHERE hostname = ? LIMIT 1", [
+ database.cursor.execute("UPDATE apis SET last_accessed = ? WHERE api_domain = ? LIMIT 1", [
time.time(),
api_domain
])