in src/mapillary/controller/save.py [0:0]
def save_as_geojson_controller(data: str, path: str, file_name: str) -> None:
"""
Save data as GeoJSON to given file path
:param data: The data to save as GeoJSON
:type data: str
:param path: The path to save to
:type path: str
:param file_name: The file name to save as
:type file_name: str
:return: None
:rtype: None
"""
# Ensure that the geojson is a dictionary
if isinstance(data, str):
data = json.loads(data)
# Ensure that the file name is valid
# Set the file name according to the given value. Default is
# "mapillary_CURRENT_UNIX_TIMESTAMP_.csv"
file_name = (
file_name
if (file_name is not None and check_file_name_validity(file_name))
else f"mapillary_{date_to_unix_timestamp('*')}_"
) + ".geojson"
try:
# Context manager for writing to file
with open(os.path.join(path, file_name), "w") as file_path:
json.dump(data, file_path, indent=4)
except Exception as e:
# If there is an error, log it
print(e)
return None