Skip to content

Commit

Permalink
The method from localization returns None if city is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ziv17 committed Aug 2, 2024
1 parent 8c23c90 commit 41708b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion anyway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import logging
from collections import namedtuple
from typing import List, Set, Iterable
from typing import List, Set, Iterable, Optional


try:
Expand Down Expand Up @@ -1105,6 +1105,13 @@ def get_name_from_symbol(symbol: int, lang: str = 'he') -> str:
raise ValueError(f"{int_sym}({symbol}): could not find city with that symbol")
return res.heb_name if lang == 'he' else res.eng_name

@staticmethod
def get_name_from_symbol_or_none(symbol: int, lang: str = 'he') -> Optional[str]:
try:
return City.get_name_from_symbol(symbol, lang)
except ValueError:
return None

@staticmethod
def get_symbol_from_name(name: str) -> int:
res: City = db.session.query(City.yishuv_symbol).filter(City.heb_name == name).first()
Expand Down
6 changes: 3 additions & 3 deletions anyway/parsers/cbs/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def get_address(accident, streets):
and int(accident.get(field_names.house_number)) != 9999
else None
)
settlement = City.get_name_from_symbol(accident.get(field_names.yishuv_symbol))
settlement = City.get_name_from_symbol_or_none(accident.get(field_names.yishuv_symbol))

if not house_number and not settlement:
return street
Expand Down Expand Up @@ -523,7 +523,7 @@ def create_marker(provider_code, accident, streets, roads, non_urban_intersectio
"km_raw": get_data_value(accident.get(field_names.km)),
"km_accurate": km_accurate,
"yishuv_symbol": get_data_value(accident.get(field_names.yishuv_symbol)),
"yishuv_name": City.get_name_from_symbol(accident.get(field_names.yishuv_symbol)),
"yishuv_name": City.get_name_from_symbol_or_none(accident.get(field_names.yishuv_symbol)),
"geo_area": get_data_value(accident.get(field_names.geo_area)),
"day_night": get_data_value(accident.get(field_names.day_night)),
"day_in_week": get_data_value(accident.get(field_names.day_in_week)),
Expand Down Expand Up @@ -603,7 +603,7 @@ def import_involved(provider_code, involved, **kwargs):
"involve_yishuv_symbol": get_data_value(
involve.get(field_names.involve_yishuv_symbol)
),
"involve_yishuv_name": City.get_name_from_symbol(
"involve_yishuv_name": City.get_name_from_symbol_or_none(
involve.get(field_names.involve_yishuv_symbol)
),
"injury_severity": get_data_value(involve.get(field_names.injury_severity)),
Expand Down

0 comments on commit 41708b2

Please sign in to comment.