Fix empty name field error in metadata saving
All checks were successful
Deployment / deploy-docker (push) Successful in 15s
All checks were successful
Deployment / deploy-docker (push) Successful in 15s
This commit is contained in:
@@ -127,16 +127,21 @@ def fetch_metadata(isin):
|
|||||||
def save_metadata(metadata):
|
def save_metadata(metadata):
|
||||||
# QuestDB Influx Line Protocol
|
# QuestDB Influx Line Protocol
|
||||||
# table,tag1=val1 field1="str",field2=num timestamp
|
# table,tag1=val1 field1="str",field2=num timestamp
|
||||||
name = metadata['name'].replace(' ', '\\ ').replace(',', '\\,')
|
|
||||||
country = metadata['country']
|
# Ensure all fields have valid non-empty values
|
||||||
continent = metadata['continent']
|
name = metadata.get('name', 'Unknown') or 'Unknown'
|
||||||
sector = metadata['sector']
|
country = metadata.get('country', 'Unknown') or 'Unknown'
|
||||||
|
continent = metadata.get('continent', 'Unknown') or 'Unknown'
|
||||||
|
sector = metadata.get('sector', 'Unknown') or 'Unknown'
|
||||||
isin = metadata['isin']
|
isin = metadata['isin']
|
||||||
|
|
||||||
|
# Escape special characters in name for Influx Line Protocol
|
||||||
|
name = name.replace(' ', '\\ ').replace(',', '\\,').replace('"', '\\"')
|
||||||
|
|
||||||
line = f'metadata,isin={isin} name="{name}",country="{country}",continent="{continent}",sector="{sector}"'
|
line = f'metadata,isin={isin} name="{name}",country="{country}",continent="{continent}",sector="{sector}"'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.post(f"http://{DB_HOST}:9000/write", data=line + "\n", auth=DB_AUTH)
|
response = requests.post(f"http://{DB_HOST}:9000/write", data=line + "\\n", auth=DB_AUTH)
|
||||||
if response.status_code not in [200, 204]:
|
if response.status_code not in [200, 204]:
|
||||||
logger.error(f"Error saving metadata: {response.text}")
|
logger.error(f"Error saving metadata: {response.text}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user