Skip to content

Commit

Permalink
refactor: revert default line length 132 --> 88 char
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jun 6, 2024
1 parent 2c9f7a9 commit 6575b8b
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 47 deletions.
19 changes: 15 additions & 4 deletions osm_rawdata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ def _yaml_parse_select_and_keep(self, data):
for table in self.config.get("tables", []):
# 'select' not tags specified, use 'where' tags instead
if data.get("select") is None:
tags = [key for entry in self.config["where"][table] for key in entry.keys() if key != "op"]
tags = [
key
for entry in self.config["where"][table]
for key in entry.keys()
if key != "op"
]
self.config["select"][table] = [{tag: {}} for tag in tags]

# 'select' tags specified, process
Expand Down Expand Up @@ -256,7 +261,9 @@ def convert_geometry(geom_type):
# FIXME needs a refactor to handle all_geometry correctly
if geom_type == "all_geometry":
for geometry_type in ["nodes", "ways_line", "ways_poly"]:
self.config["select"][geometry_type].append({attribute_name: {}})
self.config["select"][geometry_type].append(
{attribute_name: {}}
)
self.config["tables"].append(geometry_type)
else:
self.config["select"][geom_type].append({attribute_name: {}})
Expand Down Expand Up @@ -311,7 +318,9 @@ def dump(self):
keys.append(v1)
if k1 == "op":
continue
print(f"\tWhere table '{key}', tag '{k1}' has values '{v1}' {op}")
print(
f"\tWhere table '{key}', tag '{k1}' has values '{v1}' {op}"
)
else:
print(f"\tSelecting tag '{key}'")
# print("Tables")
Expand Down Expand Up @@ -344,7 +353,9 @@ def main():
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(threadName)10s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter(
"%(threadName)10s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
log.addHandler(ch)

Expand Down
12 changes: 9 additions & 3 deletions osm_rawdata/geofabrik.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action="store_true", help="verbose output")
parser.add_argument("-f", "--file", help="The country or US state to download")
parser.add_argument("-l", "--list", action="store_true", help="List all files on GeoFabrik")
parser.add_argument(
"-l", "--list", action="store_true", help="List all files on GeoFabrik"
)
args = parser.parse_args()

if len(argv) <= 1:
Expand All @@ -84,7 +86,9 @@ def main():
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(threadName)10s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter(
"%(threadName)10s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
log.addHandler(ch)

Expand All @@ -97,7 +101,9 @@ def main():
if args.file:
region = geof.getRegion(args.file)
if not region:
log.error(f"{args.file} not found on GeoFabrik! Use the -l option to list all the regions")
log.error(
f"{args.file} not found on GeoFabrik! Use the -l option to list all the regions"
)
quit()

uri = f"http://download.geofabrik.de/{region.lower()}/{args.file.lower()}-latest.osm.pbf"
Expand Down
20 changes: 16 additions & 4 deletions osm_rawdata/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def parquetThread(
tags=scalar,
)
elif hex.geom_type == "MultiPolygon":
gdata = geoalchemy2.shape.from_shape(hex.convex_hull, srid=4326, extended=True)
gdata = geoalchemy2.shape.from_shape(
hex.convex_hull, srid=4326, extended=True
)
sql = insert(ways).values(
geom=bytes(gdata.data),
tags=scalar,
Expand Down Expand Up @@ -340,7 +342,11 @@ def importParquet(
if len(overture.data[block : block + chunk]) == 0:
continue
log.debug("Dispatching Block %d:%d" % (block, block + chunk))
result = executor.submit(parquetThread, overture.data[block : block + chunk], connections[index])
result = executor.submit(
parquetThread,
overture.data[block : block + chunk],
connections[index],
)
block += chunk
index += 1
executor.shutdown()
Expand Down Expand Up @@ -387,7 +393,11 @@ def importGeoJson(
block = 0
while block <= entries:
log.debug("Dispatching Block %d:%d" % (block, block + chunk))
result = executor.submit(importThread, data["features"][block : block + chunk], self.connections[index])
result = executor.submit(
importThread,
data["features"][block : block + chunk],
self.connections[index],
)
block += chunk
index += 1
executor.shutdown()
Expand Down Expand Up @@ -420,7 +430,9 @@ def main():
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(threadName)10s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter(
"%(threadName)10s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
log.addHandler(ch)

Expand Down
8 changes: 6 additions & 2 deletions osm_rawdata/overture.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def main():
)
parser.add_argument("-v", "--verbose", action="store_true", help="verbose output")
parser.add_argument("-i", "--infile", required=True, help="Input file")
parser.add_argument("-o", "--outfile", default="overture.geojson", help="Output file")
parser.add_argument(
"-o", "--outfile", default="overture.geojson", help="Output file"
)

args = parser.parse_args()

Expand All @@ -148,7 +150,9 @@ def main():
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(threadName)10s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter(
"%(threadName)10s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
log.addHandler(ch)

Expand Down
61 changes: 48 additions & 13 deletions osm_rawdata/pgasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ async def connect(
if not uri.username:
self.dburi["dbuser"] = os.getenv("PGUSER", default=None)
if not self.dburi["dbuser"]:
log.error("You must specify the user name in the database URI, or set PGUSER")
log.error(
"You must specify the user name in the database URI, or set PGUSER"
)
else:
self.dburi["dbuser"] = uri.username
if not uri.password:
self.dburi["dbpass"] = os.getenv("PGPASSWORD", default=None)
if not self.dburi["dbpass"]:
log.error("You must specify the user password in the database URI, or set PGPASSWORD")
log.error(
"You must specify the user password in the database URI, or set PGPASSWORD"
)
else:
self.dburi["dbpass"] = uri.password
if not uri.hostname:
Expand All @@ -88,8 +92,13 @@ async def connect(

# Use a persistant connect, better for multiple requests
self.session = requests.Session()
self.url = os.getenv("RAW_DATA_API_URL", "https://raw-data-api0.hotosm.org/v1")
self.headers = {"accept": "application/json", "Content-Type": "application/json"}
self.url = os.getenv(
"RAW_DATA_API_URL", "https://raw-data-api0.hotosm.org/v1"
)
self.headers = {
"accept": "application/json",
"Content-Type": "application/json",
}
else:
# log.debug(f"Connecting with: {connect}")
try:
Expand Down Expand Up @@ -128,11 +137,20 @@ async def createJson(
# This only effects the output file
geometrytype = list()
# for table in config.config['tables']:
if len(config.config["select"]["nodes"]) > 0 or len(config.config["where"]["nodes"]) > 0:
if (
len(config.config["select"]["nodes"]) > 0
or len(config.config["where"]["nodes"]) > 0
):
geometrytype.append("point")
if len(config.config["select"]["ways_line"]) > 0 or len(config.config["where"]["ways_line"]) > 0:
if (
len(config.config["select"]["ways_line"]) > 0
or len(config.config["where"]["ways_line"]) > 0
):
geometrytype.append("line")
if len(config.config["select"]["ways_poly"]) > 0 or len(config.config["where"]["ways_poly"]) > 0:
if (
len(config.config["select"]["ways_poly"]) > 0
or len(config.config["where"]["ways_poly"]) > 0
):
geometrytype.append("polygon")
feature["geometryType"] = geometrytype

Expand Down Expand Up @@ -412,7 +430,10 @@ async def queryLocal(

# If there is no config file, don't modify the results
if self.qc:
if len(self.qc.config["where"]["ways_poly"]) == 0 and len(self.qc.config["where"]["nodes"]) == 0:
if (
len(self.qc.config["where"]["ways_poly"]) == 0
and len(self.qc.config["where"]["nodes"]) == 0
):
return result

for item in result:
Expand Down Expand Up @@ -606,11 +627,22 @@ async def main():
)
parser.add_argument("-v", "--verbose", nargs="?", const="0", help="verbose output")
parser.add_argument("-u", "--uri", default="underpass", help="Database URI")
parser.add_argument("-b", "--boundary", required=True, help="Boundary polygon to limit the data size")
parser.add_argument("-s", "--sql", help="Custom SQL query to execute against the database")
parser.add_argument(
"-b",
"--boundary",
required=True,
help="Boundary polygon to limit the data size",
)
parser.add_argument(
"-s", "--sql", help="Custom SQL query to execute against the database"
)
parser.add_argument("-a", "--all", help="All the geometry or just centroids")
parser.add_argument("-c", "--config", help="The config file for the query (json or yaml)")
parser.add_argument("-o", "--outfile", default="extract.geojson", help="The output file")
parser.add_argument(
"-c", "--config", help="The config file for the query (json or yaml)"
)
parser.add_argument(
"-o", "--outfile", default="extract.geojson", help="The output file"
)
args = parser.parse_args()

# if len(argv) <= 1 or (args.sql is None and args.config is None):
Expand All @@ -624,7 +656,10 @@ async def main():

logging.basicConfig(
level=log_level,
format=("%(asctime)s.%(msecs)03d [%(levelname)s] " "%(name)s | %(funcName)s:%(lineno)d | %(message)s"),
format=(
"%(asctime)s.%(msecs)03d [%(levelname)s] "
"%(name)s | %(funcName)s:%(lineno)d | %(message)s"
),
datefmt="%y-%m-%d %H:%M:%S",
stream=sys.stdout,
)
Expand Down
Loading

0 comments on commit 6575b8b

Please sign in to comment.