better structure
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m45s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 45s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s

This commit is contained in:
2025-02-19 15:53:41 +01:00
parent 83be4b7616
commit 05092e55f1
9 changed files with 88 additions and 64 deletions

View File

@@ -1,5 +1,6 @@
"""Module allowing connexion to overpass api and fectch data from OSM."""
import os
import time
import urllib
import math
import logging
@@ -153,7 +154,7 @@ class Overpass :
- If no conditions are provided, the query will just use the `selector` to filter the OSM
elements without additional constraints.
"""
query = '[out:json];('
query = '[out:json][timeout:20];('
# convert the bbox to string.
bbox_str = f"({','.join(map(str, bbox))})"
@@ -399,18 +400,25 @@ def fill_cache():
"""
overpass = Overpass()
n_files = 0
total = 0
with os.scandir(OSM_CACHE_DIR) as it:
for entry in it:
if entry.is_file() and entry.name.startswith('hollow_'):
total += 1
try :
# Read the whole file content as a string
with open(entry.path, 'r', encoding='utf-8') as f:
# load data and fill the cache with the query and key
json_data = json.load(f)
overpass.fill_cache(json_data)
n_files += 1
time.sleep(1)
# Now delete the file as the cache is filled
os.remove(entry.path)
except Exception as exc :
overpass.logger.error(f'An error occured while parsing file {entry.path} as .json file: {str(exc)}')
overpass.logger.info(f"Successfully filled {n_files}/{total} cache files.")