fix: do not hard fail on missing meta data

This commit is contained in:
William Luke 2022-05-01 09:18:45 +03:00
parent 1dba2d09d1
commit 0db8e56603
3 changed files with 14 additions and 23 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ build/
*.pyc *.pyc
.venv .venv
.clicada .clicada
dist/ dist/
.vscode/

View File

@ -82,31 +82,21 @@ def execute(ctrl):
user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter) user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
ctrl.notify('resolving metadata for address {}'.format(user_address_normal)) ctrl.notify('resolving metadata for address {}'.format(user_address_normal))
r = None
try: try:
r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE')) r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE'))
except MetadataNotFoundError as e: except MetadataNotFoundError as e:
ctrl.ouch('could not resolve metadata for user: {}'.format(e)) ctrl.ouch('could not resolve metadata for user: {}'.format(e))
sys.exit(1)
ctrl.write("""Phone: {} ctrl.write(f"""Phone: {ctrl.get('_IDENTIFIER')}
Network address: {} Network address: {add_0x(user_address)}
Chain: {} Chain: {ctrl.chain().common_name()}
Name: {} Name: {str(r)}
Registered: {} Registered: {r and datetime.datetime.fromtimestamp(r).ctime()}
Gender: {} Gender: {r and r.gender}
Location: {} Location: {r and r.location['area_name']}
Products: {} Products: {r and ','.join(r.products)}
Tags: {}""".format( Tags: {r and ','.join(r.tags)}"""
ctrl.get('_IDENTIFIER'),
add_0x(user_address),
ctrl.chain().common_name(),
str(r),
datetime.datetime.fromtimestamp(r.date_registered).ctime(),
r.gender,
r.location['area_name'],
','.join(r.products),
','.join(r.tags),
)
) )
tx_lines = [] tx_lines = []

View File

@ -12,7 +12,7 @@ from cic_types.condiments import MetadataPointer
from cic_types.models.person import Person from cic_types.models.person import Person
from cic_types.ext.requests import make_request from cic_types.ext.requests import make_request
from cic_types.processor import generate_metadata_pointer from cic_types.processor import generate_metadata_pointer
import requests.exceptions from requests.exceptions import HTTPError
import phonenumbers import phonenumbers
# local imports # local imports
@ -222,7 +222,7 @@ class FileUserStore:
try: try:
r = getter.open(ptr) r = getter.open(ptr)
user_address = json.loads(r) user_address = json.loads(r)
except requests.exceptions.HTTPError as e: except HTTPError as e:
logg.debug('no address found for phone {}: {}'.format(phone, e)) logg.debug('no address found for phone {}: {}'.format(phone, e))
return None return None