Commit 8ff373bd authored by Federico Sismondi's avatar Federico Sismondi

Update() text cleaner for special chars in ngsiv2 tranlsator module. Fix()...

Update() text cleaner for special chars in ngsiv2 tranlsator module. Fix() dateformat from ISO to Z format
parent f2c213ec
......@@ -54,9 +54,17 @@ def get_ngsiv2_typed_description(val):
elif isinstance(val, int) or isinstance(val, float):
return {'type': 'Number', 'value': val}
elif isinstance(val, str):
return {'type': 'Text', 'value': val}
# do some special chars cleaning
special_chars = ["'", "(", ")", "{", "}", "|"]
unaccented_comment = unidecode.unidecode(val)
for ch in special_chars:
unaccented_comment = unaccented_comment.replace(ch, "")
app.logger.warning("Special char deleted. This <{}> turned into this <{}>".format(val,unaccented_comment))
return {'type': 'Text', 'value': unaccented_comment}
elif isinstance(val, datetime.datetime):
return {'type': 'DateTime', 'value': val.isoformat()}
# replace +00:00 is the same as Z but Orion doesnt like it :/
return {'type': 'DateTime', 'value': str(val.isoformat()).replace("+00:00", "Z")}
elif isinstance(val, dict):
return {'value': val} # bypassed
elif isinstance(val, list):
......@@ -215,12 +223,7 @@ def _forward_lora_dev_data_to_ctx_broker(deveui, comment, longitude, latitude, l
body.update({'location': get_ngsiv2_typed_description(Point([longitude, latitude]))})
if comment:
# do some special chars cleaning
unaccented_comment = unidecode.unidecode(comment)
unaccented_comment = unaccented_comment.replace("'", "")
unaccented_comment = unaccented_comment.replace("(", "")
unaccented_comment = unaccented_comment.replace(")", "")
body.update({'description': get_ngsiv2_typed_description(unaccented_comment)})
body.update({'description': get_ngsiv2_typed_description(comment)})
# parse device name hiden inside comment field
pattern = r'{device_name}=([^\s]+)'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment