logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
+#logger.setLevel(logging.DEBUG)
# Found info from node, such as nodeinfo URL, detection mode that needs to be
# written to database. Both arrays must be filled at the same time or else
-# update_data() will fail
+# update() will fail
_pending = {
# Detection mode
# NULL means all detection methods have failed (maybe still reachable instance)
logger.debug("has='%s' - EXIT!", has)
return has
-def update_data(domain: str):
+def update(domain: str):
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
if not has_pending(domain):
logger.debug("sql_string(%d)='%s'", len(sql_string), sql_string)
if sql_string == "":
- raise ValueError(f"No fields have been set, but method invoked, domain='{domain}'")
+ raise ValueError(f"No fields have been set, but function invoked, domain='{domain}'")
# Set last_updated to current timestamp
fields.append(time.time())
elif origin is not None and not validators.domain(origin.split("/")[0]):
raise ValueError(f"Bad origin name='{origin}'")
elif blacklist.is_blacklisted(domain):
- raise Exception(f"domain='{domain}' is blacklisted, but method invoked")
+ raise Exception(f"domain='{domain}' is blacklisted, but function invoked")
elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (is_registered(domain.split("/")[0]) and domain.find("/c/") > 0):
raise Exception(f"domain='{domain}' is a single user")
elif domain.find("/tag/") > 0:
logger.debug("Checking if domain='%s' has pending updates ...", domain)
if has_pending(domain):
logger.debug("Flushing updates for domain='%s' ...", domain)
- update_data(domain)
+ update(domain)
logger.debug("EXIT!")
if not isinstance(column, str):
raise ValueError(f"Parameter column[]='{type(column)}' is not of type 'str'")
- elif column not in ["last_instance_fetch", "last_blocked", "last_nodeinfo"]:
+ elif not column.startswith("last_"):
raise ValueError(f"Parameter column='{column}' is not expected")
elif not is_registered(domain):
logger.debug("domain='%s' is not registered, returning False - EXIT!", domain)
database.cursor.execute(f"SELECT {column} FROM instances WHERE domain = ? LIMIT 1", [domain])
# Fetch row
- fetched = database.cursor.fetchone()[column]
+ row = database.cursor.fetchone()
- logger.debug("fetched[%s]='%s',key='%s'", type(fetched), fetched, key)
- recently = isinstance(fetched, float) and (time.time() - fetched) >= config.get(key)
+ fetched = float(row[column]) if row[column] is not None else 0.0
+
+ diff = (time.time() - fetched)
+
+ logger.debug("fetched[%s]='%s',key='%s',diff=%f", type(fetched), fetched, key, diff)
+ recently = bool(diff < config.get(key))
logger.debug("recently='%s' - EXIT!", recently)
return recently
domain_helper.raise_on(domain)
if not isinstance(obfuscated, int):
- raise ValueError(f"Parameter obfuscated[]='{type(blocks)}' is not of type 'int'")
+ raise ValueError(f"Parameter obfuscated[]='{type(obfuscated)}' is not of type 'int'")
elif obfuscated < 0:
raise ValueError(f"Parameter obfuscated={obfuscated} is not valid")