fantoir voie: limite de recherche et recherche ''
This commit is contained in:
parent
01c8f2b37b
commit
3f7d4b6331
5 changed files with 30 additions and 36 deletions
|
@ -14,22 +14,17 @@ DB_COL_COMMUNE_INSEE = "Code_commune_INSEE"
|
||||||
DB_COL_COMMUNE_NAME = "Nom_commune"
|
DB_COL_COMMUNE_NAME = "Nom_commune"
|
||||||
DB_COL_COMMUNE_POSTE = "Code_postal"
|
DB_COL_COMMUNE_POSTE = "Code_postal"
|
||||||
|
|
||||||
# Table for Fantoir voies (code Rivoli)
|
|
||||||
DB_TABLE_FANTOIR_NAME = "keyv"
|
|
||||||
DB_COL_FANTOIR_INSEE = "key"
|
|
||||||
DB_FANTOIR_INSEE_KEY_SUFFIX = "keyv:"
|
|
||||||
|
|
||||||
# Utility to find an address
|
# Utility to find an address
|
||||||
|
|
||||||
|
|
||||||
class AddressFinder:
|
class AddressFinder:
|
||||||
|
|
||||||
def __init__(self, db_addresses_sqlite_path: str):
|
def __init__(self, db_insee_communes_sqlite_path: str, db_fantoir_voies_sqlite_path: str):
|
||||||
self.dbPath = db_addresses_sqlite_path
|
self.dbCommunesPath = db_insee_communes_sqlite_path
|
||||||
print("DB addresses Path : " + self.dbPath)
|
self.dbFantoirPath = db_fantoir_voies_sqlite_path
|
||||||
|
print("DB insee communes Path : " + self.dbCommunesPath)
|
||||||
|
print("DB Fantoir voies Path : " + self.dbFantoirPath)
|
||||||
|
|
||||||
def getCommunesFromNameOrZip(self, communeNameOrZip: str, limit: int = None) -> list[Commune]:
|
def getCommunesFromNameOrZip(self, communeNameOrZip: str, limit: int = None) -> list[Commune]:
|
||||||
con = sqlite3.connect(self.dbPath)
|
con = sqlite3.connect(self.dbCommunesPath)
|
||||||
con.row_factory = sqlite3.Row
|
con.row_factory = sqlite3.Row
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
|
||||||
|
@ -80,25 +75,29 @@ class AddressFinder:
|
||||||
def getCommuneFantoirVoies(self, communeInseeCode: str, voieSearch: str = None, limit: int = None) -> list[FantoirVoie]:
|
def getCommuneFantoirVoies(self, communeInseeCode: str, voieSearch: str = None, limit: int = None) -> list[FantoirVoie]:
|
||||||
|
|
||||||
# Extract data from DB
|
# Extract data from DB
|
||||||
con = sqlite3.connect(self.dbPath)
|
con = sqlite3.connect(self.dbFantoirPath)
|
||||||
con.row_factory = sqlite3.Row
|
con.row_factory = sqlite3.Row
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
if voieSearch is None:
|
||||||
|
voieSearch=''
|
||||||
|
|
||||||
|
# Check if a search limit is specified, make sure it is an integer
|
||||||
|
select_limit = ""
|
||||||
|
if limit is not None:
|
||||||
|
try:
|
||||||
|
select_limit = f"LIMIT {int(limit)}"
|
||||||
|
except ValueError:
|
||||||
|
print("Error, limit arg not a valid int: ", limit)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
f"SELECT trim(libelle), rivoli_with_key from fantoir WHERE full_insee=\"{communeInseeCode}\" AND libelle like \"%{voieSearch}%\"")
|
f"SELECT trim(libelle), rivoli_with_key from fantoir WHERE full_insee=\"{communeInseeCode}\" AND libelle like \"%{voieSearch}%\" {select_limit}")
|
||||||
except sqlite3.OperationalError as err:
|
except sqlite3.OperationalError as err:
|
||||||
print("Error querying DB : {0}".format(err), file=sys.stderr)
|
print("Error querying DB : {0}".format(err), file=sys.stderr)
|
||||||
return []
|
return []
|
||||||
data_raw = cur.fetchall()
|
data_raw = cur.fetchall()
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
# Check if a search limit is specified, make sure it is an integer
|
|
||||||
if limit is not None:
|
|
||||||
try:
|
|
||||||
limit = int(limit)
|
|
||||||
except ValueError:
|
|
||||||
print("Error, limit arg not a valid int: ", limit)
|
|
||||||
|
|
||||||
fantoir_dict = []
|
fantoir_dict = []
|
||||||
# Check if data where found
|
# Check if data where found
|
||||||
if data_raw is not None:
|
if data_raw is not None:
|
||||||
|
|
|
@ -6,12 +6,5 @@ class Commune(TypedDict):
|
||||||
codeZip: str
|
codeZip: str
|
||||||
|
|
||||||
class FantoirVoie(TypedDict):
|
class FantoirVoie(TypedDict):
|
||||||
id: str
|
libelle: str
|
||||||
dateAjout: int
|
rivoli_with_key: int
|
||||||
libelle: list[str]
|
|
||||||
typeVoie:str
|
|
||||||
codeCommune: str
|
|
||||||
codeFantoir: str
|
|
||||||
cleRivoli: str
|
|
||||||
nomCommune: str
|
|
||||||
predecesseur: bool
|
|
||||||
|
|
|
@ -2,11 +2,12 @@ import configparser
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, username, password, source_addr, db_addresses_sqlite_path):
|
def __init__(self, username, password, source_addr, db_insee_communes_sqlite_path, db_fantoir_voies_sqlite_path):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.source_addr = source_addr
|
self.source_addr = source_addr
|
||||||
self.db_addresses_sqlite_path = db_addresses_sqlite_path
|
self.db_insee_communes_sqlite_path = db_insee_communes_sqlite_path
|
||||||
|
self.db_fantoir_voies_sqlite_path = db_fantoir_voies_sqlite_path
|
||||||
self.debug = False
|
self.debug = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,5 +18,6 @@ def parse_config(cfgPath):
|
||||||
username = cfg.get("API", "username")
|
username = cfg.get("API", "username")
|
||||||
passwd = cfg.get("API", "password")
|
passwd = cfg.get("API", "password")
|
||||||
source_addr = cfg.get("API", "source_addr")
|
source_addr = cfg.get("API", "source_addr")
|
||||||
db_addresses_sqlite_path = cfg.get("ADDRESSES","db_addresses_sqlite_path")
|
db_insee_communes_sqlite_path = cfg.get("ADDRESSES","db_insee_communes_sqlite_path")
|
||||||
return Config(username, passwd, source_addr,db_addresses_sqlite_path)
|
db_fantoir_voies_sqlite_path = cfg.get("ADDRESSES","db_fantoir_voies_sqlite_path")
|
||||||
|
return Config(username, passwd, source_addr,db_insee_communes_sqlite_path, db_fantoir_voies_sqlite_path)
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
<form method="post" action="/test/address">
|
<form method="post" action="/test/address">
|
||||||
<div class="form-group" id="communeForm">
|
<div class="form-group" id="communeForm">
|
||||||
<label class="form-label" for="communeInput">Commune</label>
|
<label class="form-label" for="communeInput">Commune</label>
|
||||||
<input type="text" list="communes" name="commune" class="form-control" id="communeInput" ondblclick="this.focus();this.select()" aria-describedby="communeHelp" placeholder="Nom de la commune ou code postal">
|
<input autocomplete="off" type="text" list="communes" name="commune" class="form-control" id="communeInput" ondblclick="this.focus();this.select()" aria-describedby="communeHelp" placeholder="Nom de la commune ou code postal">
|
||||||
<datalist id="communes">
|
<datalist id="communes">
|
||||||
</datalist>
|
</datalist>
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-9 my-1">
|
<div class="col-sm-9 my-1">
|
||||||
<label class="form-label" for="voieInput">Nom de voie</label>
|
<label class="form-label" for="voieInput">Nom de voie</label>
|
||||||
<input type="text" name="voie" list="voies" class="form-control" id="voieInput" aria-describedby="voieHelp" placeholder="Nom de voie">
|
<input autocomplete="off" type="text" name="voie" list="voies" class="form-control" id="voieInput" aria-describedby="voieHelp" placeholder="Nom de voie">
|
||||||
<datalist id="voies">
|
<datalist id="voies">
|
||||||
</datalist>
|
</datalist>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,7 +22,7 @@ def load_config():
|
||||||
|
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
|
|
||||||
addressFinder = AddressFinder(cfg.db_addresses_sqlite_path)
|
addressFinder = AddressFinder(cfg.db_insee_communes_sqlite_path, cfg.db_fantoir_voies_sqlite_path)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue