Skip to content

Commit

Permalink
Merge pull request #200 from dataforgoodfr/fix/divers
Browse files Browse the repository at this point in the history
Fix #198
  • Loading branch information
njouanin authored Jul 15, 2024
2 parents 9d2a638 + 8cbad96 commit 711feec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
36 changes: 19 additions & 17 deletions backend/bloom/tasks/load_spire_data_from_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@ def run(dump_path: str) -> None:
try:
with db.session() as session:
vessels: list[Vessel] = vessel_repository.get_vessels_list(session)

raw_vessels = spire_traffic_usecase.get_raw_vessels_from_spire(vessels)
if dump_path is not None:
try:
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
dump_file = Path(args.dump_path, f"spire_{now}").with_suffix(".json")
with dump_file.open("wt") as handle:
json.dump(raw_vessels, handle)
except Exception as e:
logger.warning("Echec de l'écriture de la réponse Spire", exc_info=e)
else:
spire_ais_data = map_raw_vessels_to_domain(raw_vessels)
orm_data = spire_ais_data_repository.batch_create_ais_data(
spire_ais_data,
session,
)
session.commit()
if len(vessels) > 0:
raw_vessels = spire_traffic_usecase.get_raw_vessels_from_spire(vessels)
if dump_path is not None:
try:
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
dump_file = Path(args.dump_path, f"spire_{now}").with_suffix(".json")
with dump_file.open("wt") as handle:
json.dump(raw_vessels, handle)
except Exception as e:
logger.warning("Echec de l'écriture de la réponse Spire", exc_info=e)
else:
spire_ais_data = map_raw_vessels_to_domain(raw_vessels)
orm_data = spire_ais_data_repository.batch_create_ais_data(
spire_ais_data,
session,
)
session.commit()
except ValidationError as e:
logger.error("Erreur de validation des données JSON")
logger.error(e.errors())
raise e
except Exception as e:
logger.error("Echec de l'appel API", exc_info=e)
raise e
logger.info(f"{len(orm_data)} données chargées")


Expand Down
5 changes: 5 additions & 0 deletions etl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/sh

python backend/bloom/tasks/load_spire_data_from_api.py && \
python backend/bloom/tasks/clean_positions.py && \
python backend/bloom/tasks/create_update_excursions_segments.py

0 comments on commit 711feec

Please sign in to comment.