X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fetch_bkali.py;h=f6b6fdb2e6c55919d36e7680917d0babe415e003;hb=ad0e8ee96f0dd23c04e491b01a23000b63cab854;hp=f09612df3b5a16fce8fb5b140d63689808be2ee6;hpb=9570b6a381993adccd031ca8dc6a7d6e95e64c5d;p=fba.git diff --git a/fetch_bkali.py b/fetch_bkali.py index f09612d..f6b6fdb 100755 --- a/fetch_bkali.py +++ b/fetch_bkali.py @@ -20,7 +20,9 @@ import json import sys import validators -import fba +from fba import * + +boot.lock_process() domains = list() try: @@ -29,20 +31,30 @@ try: })) # DEBUG: print(f"DEBUG: fetched({len(fetched)})[]='{type(fetched)}'") - if len(fetched) > 0 and "data" in fetched and "nodeinfo" in fetched["data"]: - for entry in fetched["data"]["nodeinfo"]: - # DEBUG: print(f"DEBUG: entry['{type(entry)}']='{entry}'") - if not "domain" in entry: - print(f"WARNING: entry does not contain 'domain' - SKIPPED!") - continue - elif not validators.domain(entry["domain"]): - print(f"WARNING: domain='{entry['domain']}' is {entry['domain']}' is not a valid domain - SKIPPED!") - continue - elif fba.is_blacklisted(entry["domain"]): - # DEBUG: print(f"DEBUG: domain='blacklisted - SKIPPED!") - continue - - domains.append(entry["domain"]) + if len(fetched) == 0: + raise Exception("WARNING: Returned no records") + elif not "data" in fetched: + raise Exception(f"WARNING: fetched()={len(fetched)} does not contain element 'data'") + elif not "nodeinfo" in fetched["data"]: + raise Exception(f"WARNING: fetched()={len(fetched['data'])} does not contain element 'nodeinfo'") + + for entry in fetched["data"]["nodeinfo"]: + # DEBUG: print(f"DEBUG: entry['{type(entry)}']='{entry}'") + if not "domain" in entry: + print(f"WARNING: entry does not contain 'domain' - SKIPPED!") + continue + elif not validators.domain(entry["domain"]): + print(f"WARNING: domain='{entry['domain']}' is not a valid domain - SKIPPED!") + continue + elif fba.is_blacklisted(entry["domain"]): + # DEBUG: print(f"DEBUG: domain='{entry['domain']}' is blacklisted - SKIPPED!") + continue + elif fba.is_instance_registered(entry["domain"]): + # DEBUG: print(f"DEBUG: domain='{entry['domain']}' is already registered - SKIPPED!") + continue + + # DEBUG: print(f"DEBUG: Adding domain='{entry['domain']}' ...") + domains.append(entry["domain"]) except BaseException as e: print(f"ERROR: Cannot fetch graphql,exception[{type(e)}]:'{str(e)}'") @@ -56,4 +68,4 @@ if len(domains) > 0: print(f"INFO: Fetching instances from domain='{domain}' ...") fba.fetch_instances(domain, None, None, sys.argv[0]) -fba.connection.close() +boot.shutdown()