Skip to content

Commit

Permalink
Merge pull request #13 from tgrandje/dev
Browse files Browse the repository at this point in the history
Update french-cities depedencies
  • Loading branch information
tgrandje authored Aug 5, 2024
2 parents f9c4b47 + cd4b7fb commit 238eaf4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
11 changes: 5 additions & 6 deletions french_cities/city_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from french_cities import DIR_CACHE
from french_cities.vintage import set_vintage
from french_cities.departement_finder import find_departements
from french_cities.utils import init_pynsee, patch_the_patch
from french_cities.utils import init_pynsee
from french_cities.ultramarine_pseudo_cog import get_cities_and_ultramarines


Expand Down Expand Up @@ -1014,11 +1014,10 @@ def _query_BAN_csv_geocoder(
("result_columns", (None, "result_citycode")),
]

with patch_the_patch():
r = session.post(
"https://api-adresse.data.gouv.fr/search/csv/",
files=files,
)
r = session.post(
"https://api-adresse.data.gouv.fr/search/csv/",
files=files,
)
if not r.ok:
raise Exception(
f"Failed to query BAN's API with {files=} - response was {r}"
Expand Down
13 changes: 6 additions & 7 deletions french_cities/departement_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from unidecode import unidecode

from french_cities import DIR_CACHE
from french_cities.utils import init_pynsee, patch_the_patch
from french_cities.utils import init_pynsee
from french_cities.ultramarine_pseudo_cog import (
get_departements_and_ultramarines,
)
Expand Down Expand Up @@ -139,12 +139,11 @@ def _process_departements_from_postal(
("result_columns", (None, "result_context")),
]

with patch_the_patch():
r = session.post(
# recherche grâce à l'API de la BAN
"https://api-adresse.data.gouv.fr/search/csv/",
files=files,
)
r = session.post(
# recherche grâce à l'API de la BAN
"https://api-adresse.data.gouv.fr/search/csv/",
files=files,
)

if not r.ok:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion french_cities/ultramarine_pseudo_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_ultramarines_cities(
"""

area = "collectivitesDOutreMer"
um = get_area_list(area, date, update)
um = get_area_list(area, date, update, silent=True)
if date == "*":
warning = (
f"get_descending_area with {area=} does not support date='*': "
Expand Down
14 changes: 0 additions & 14 deletions french_cities/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-

from contextlib import contextmanager
import diskcache
import os
from pathlib import Path

import pynsee.utils
from pynsee.utils.init_conn import init_conn
import requests_cache

from french_cities import DIR_CACHE

Expand Down Expand Up @@ -38,15 +36,3 @@ def init_pynsee():
keys = ["insee_key", "insee_secret", "http_proxy", "https_proxy"]
kwargs = {x: os.environ[x] for x in keys if x in os.environ}
init_conn(**kwargs)


@contextmanager
def patch_the_patch():
"""
Patches the multipart form boundary and prevent underscore (crashing the
BAN webserver)
"""
init_val = requests_cache._utils.FORM_BOUNDARY
requests_cache._utils.FORM_BOUNDARY = "requests-cache-form-boundary"
yield
requests_cache._utils.FORM_BOUNDARY = init_val
10 changes: 7 additions & 3 deletions french_cities/vintage.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get_city(x: str, starting_dates: list, projection_date: str) -> str:
break
try:
return df.at[0, "code"]
except (ValueError, AttributeError):
except (ValueError, AttributeError, KeyError):
logger.error("No projection found for city %s", x)
return None

Expand Down Expand Up @@ -307,7 +307,11 @@ def _get_parents_from_serie(
"""
parents = []
func = partial(
get_ascending_area, area=type_, date=f"{year}-01-01", type="commune"
get_ascending_area,
area=type_,
date=f"{year}-01-01",
type="commune",
silent=True,
)
for code in tqdm(codes, desc="get parent from insee", leave=False):
parents.append(
Expand Down Expand Up @@ -349,7 +353,7 @@ def _get_subareas_year(
4 13205 13055
"""
subareas = get_area_list(area=type_, date=f"{year}-01-01")
subareas = get_area_list(area=type_, date=f"{year}-01-01", silent=True)
try:
subareas = subareas.drop("DATE_DELETION", axis=1)
except KeyError:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "french-cities"
version = "1.0.0"
version = "1.0.1"
description = "Toolbox on french cities: set vintage, find departments, find cities..."
authors = ["thomas.grandjean <[email protected]>"]
license = "GPL-3.0-or-later"
Expand All @@ -22,13 +22,13 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.9"
requests-cache = "^1.1.0"
requests-cache = "^1.2.1"
unidecode = "^1.3.6"
python-dotenv = "^1.0.0"
pandas = "^2.2.2"
geopandas = "^0.14.4"
rapidfuzz = "^3.1.1"
pynsee = "^0.1.7"
pynsee = "^0.1.8"
pebble = "^5.0.3"
tqdm = "^4.65.0"
importlib-metadata = "^6.8.0"
Expand Down

0 comments on commit 238eaf4

Please sign in to comment.