Commit a371da34 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Use black

parent 6628652f
......@@ -27,13 +27,13 @@ def compute_description(row, met_cursor):
""" Compute (sort of) wiki description """
data = {
'nom': row['nom'],
'type': row['type'],
'metrics': mc.compute_metrics_tree(row['siren'], met_cursor)
"nom": row["nom"],
"type": row["type"],
"metrics": mc.compute_metrics_tree(row["siren"], met_cursor),
fd = io.StringIO()
mc.write_md_content(data, fd, with_title=False, mode='geo')
mc.write_md_content(data, fd, with_title=False, mode="geo")
desc =
......@@ -50,18 +50,18 @@ def output_feature(fd, row, metrics_cursor):
""" Outputs feature information """
props = {
'name': row['nom'],
'description': compute_description(row, metrics_cursor)
"name": row["nom"],
"description": compute_description(row, metrics_cursor),
feature_data = {
'id': row['siren'],
'properties': props,
'type': 'Feature',
'geometry': manage_geom(row['coords']),
"id": row["siren"],
"properties": props,
"type": "Feature",
"geometry": manage_geom(row["coords"]),
fd.write(json.dumps(feature_data, ensure_ascii=False, sort_keys=True, double_precision=2))
fd.write(json.dumps(feature_data, ensure_ascii=False, sort_keys=True))
def generate_geojson_file(category, conn, geojson_filepath: Path):
......@@ -69,17 +69,23 @@ def generate_geojson_file(category, conn, geojson_filepath: Path):
metrics_cursor = conn.cursor()
cursor = conn.cursor()
type_constraints = "= '{}'".format(category) if category != 'EPCI' else "IN ('CA', 'CC', 'CU', 'MET', 'EPT')"
type_constraints = (
"= '{}'".format(category)
if category != "EPCI"
else "IN ('CA', 'CC', 'CU', 'MET', 'EPT')"
sql_select = """SELECT * FROM orga_geometry
WHERE type {}
AND coords != ''""".format(type_constraints)
AND coords != ''""".format(
rows = cursor.fetchall()
metrics_cursor = conn.cursor()
with'wt', encoding='utf-8') as gj_fd:
with"wt", encoding="utf-8") as gj_fd:
......@@ -95,23 +101,23 @@ def generate_geojson_file(category, conn, geojson_filepath: Path):
def main():
""" Generates Geo JSON file """
parser = argparse.ArgumentParser()
parser.add_argument('db_file', type=Path, help='SQLite database file')
parser.add_argument('output_dir', type=Path, help='Where to generate GeoJSON files')
parser.add_argument("db_file", type=Path, help="SQLite database file")
parser.add_argument("output_dir", type=Path, help="Where to generate GeoJSON files")
args = parser.parse_args()
if not args.db_file.is_file():
parser.error('SQLite DB file [{}] not found'.format(str(args.db_file)))
parser.error("SQLite DB file [{}] not found".format(str(args.db_file)))
if not args.output_dir.is_dir():
parser.error('GeoJSON output dir [{}] not found'.format(str(args.output_dir)))
parser.error("GeoJSON output dir [{}] not found".format(str(args.output_dir)))
conn = sqlite3.connect(str(args.db_file))
conn.row_factory = sqlite3.Row
for cat in ('REG', 'DEP', 'COM', 'EPCI', 'AGCT', 'OACT', 'DSPT'):
for cat in ("REG", "DEP", "COM", "EPCI", "AGCT", "OACT", "DSPT"):
geojson_filepath = args.output_dir / 'odservatoire_{}.json'.format(cat.lower())
geojson_filepath = args.output_dir / "odservatoire_{}.json".format(cat.lower())
generate_geojson_file(cat, conn, geojson_filepath)
if __name__ == '__main__':
if __name__ == "__main__":
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment