From 0da7e80af47cc4a8f4cf191c22aaa612205d0e41 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:12:07 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- osm_rawdata/config.py | 3 +-- osm_rawdata/pgasync.py | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/osm_rawdata/config.py b/osm_rawdata/config.py index 17bf45f..8de7488 100755 --- a/osm_rawdata/config.py +++ b/osm_rawdata/config.py @@ -283,8 +283,7 @@ def convert_geometry(geom_type): return self.config def getKeys(self): - """ - """ + """ """ keys = list() # The first column returned is always the geometry keys.append("geometry") diff --git a/osm_rawdata/pgasync.py b/osm_rawdata/pgasync.py index c2e828e..677e665 100755 --- a/osm_rawdata/pgasync.py +++ b/osm_rawdata/pgasync.py @@ -30,7 +30,6 @@ from io import BytesIO from pathlib import Path from urllib.parse import urlparse -import flatdict import asyncpg import geojson @@ -201,11 +200,11 @@ async def createJson( feature["centroid"] = true return json.dumps(feature) - async def recordsToFeatures(self, - records: list, - ) -> list: - """ - Convert an asyncpg.Record to a GeoJson FeatureCollection. + async def recordsToFeatures( + self, + records: list, + ) -> list: + """Convert an asyncpg.Record to a GeoJson FeatureCollection. Args: records (list): The records from an SQL query @@ -226,7 +225,7 @@ async def recordsToFeatures(self, elif entry[i] is not None: props[keys[i]] = entry[i] i += 1 - data.append(Feature(geometry = geom, properties = props)) + data.append(Feature(geometry=geom, properties=props)) return data @@ -406,8 +405,7 @@ async def execute( self, sql: str, ) -> list: - """ - Execute a raw SQL query and return the results. + """Execute a raw SQL query and return the results. Args: sql (str): The SQL to execute @@ -417,16 +415,16 @@ async def execute( """ # print(sql) data = list() - if sql.find(';') <= 0: + if sql.find(";") <= 0: queries = [sql] async with self.pg.transaction(): queries = list() # If using an SRID, we have to hide the sem-colon so the string # doesn't split in the wrong place. - cmds = sql.replace("SRID=4326;P", "SRID=4326@P").split(';') + cmds = sql.replace("SRID=4326;P", "SRID=4326@P").split(";") for sub in cmds: - queries.append(sub.replace('@', ';')) + queries.append(sub.replace("@", ";")) continue for query in queries: @@ -650,7 +648,7 @@ async def execQuery( if "geometry" in boundary: polygons.append(boundary["geometry"]) - if boundary['type'] == "MultiPolygon": + if boundary["type"] == "MultiPolygon": # poly = boundary["features"][0]["geometry"] points = list() for coords in boundary["features"]["coordinates"]: @@ -671,7 +669,7 @@ async def execQuery( alldata = list() queries = list() if type(sql) != list: - queries = sql.split(';') + queries = sql.split(";") else: queries = sql @@ -689,6 +687,7 @@ async def execQuery( return collection + async def main(): """This main function lets this class be run standalone by a bash script.""" parser = argparse.ArgumentParser( @@ -743,10 +742,10 @@ async def main(): if args.boundary: infile = open(args.boundary, "r") inpoly = geojson.load(infile) - if inpoly['type'] == "MultiPolygon": + if inpoly["type"] == "MultiPolygon": poly = FeatureCollection(inpoly) else: - log.error(f"A boundary file is needed!") + log.error("A boundary file is needed!") if args.uri is not None: log.info("Using a Postgres database for the data source")