Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 12, 2024
1 parent 975349a commit 114c5f8
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions osm_rawdata/pgasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import requests
from geojson import Feature, FeatureCollection, Polygon
from shapely import wkt
from shapely.geometry import Polygon, shape
from shapely.geometry import shape

# Find the other files for this project
import osm_rawdata as rw
Expand Down Expand Up @@ -293,12 +293,13 @@ async def createTable(

return True

async def getRecordCount(self,
table: str,
column: str = 'id',
):
async def getRecordCount(
self,
table: str,
column: str = "id",
):
# FIXME: we should cleanup this mess between US and British spelling
if table == 'organizations':
if table == "organizations":
newtable = "organisations"
else:
newtable = table
Expand All @@ -310,15 +311,16 @@ async def getRecordCount(self,
# print(sql)
result = await self.execute(sql)
else:
count = result[0].get('count')
count = result[0].get("count")

log.debug(f"There are {count} records in {table}")
return count

async def getPage(self,
chunk: int,
table: str,
):
async def getPage(
self,
chunk: int,
table: str,
):
"""Return a page of data.
Args:
Expand All @@ -330,18 +332,18 @@ async def getPage(self,
"""
result = list()
async with self.pg.transaction():
cur = await self.pg.cursor(f'SELECT * FROM {table}')
cur = await self.pg.cursor(f"SELECT * FROM {table}")
result = await cur.fetch(chunk)
await cur.forward(chunk)
# FIXME: the hard way
# sql = f"DECLARE c CURSOR WITH HOLD FOR SELECT row_to_json({table}) AS row FROM {table} WHERE id BETWEEN {start} AND {end} ORDER BY id; COMMIT"
# sql = f"START TRANSACTION;DECLARE c CURSOR WITH HOLD FOR SELECT row_to_json({table}) AS row FROM {table} WHERE id BETWEEN {start} AND {end} ORDER BY id; COMMIT"
#result = await self.pg.execute(sql)
#sql = f"FETCH {end} FROM c;"
# sql = f"FETCH {end} FROM c; CLOSE c"
# result = await self.pg.execute(sql)
#result = await self.pg.fetch(sql)
# sql = f"MOVE ABSOLUTE {start} in c;
# result = await self.pg.execute(sql)
# sql = f"FETCH {end} FROM c;"
# sql = f"FETCH {end} FROM c; CLOSE c"
# result = await self.pg.execute(sql)
# result = await self.pg.fetch(sql)
# sql = f"MOVE ABSOLUTE {start} in c;

return result

Expand Down

0 comments on commit 114c5f8

Please sign in to comment.