Skip to content

Commit

Permalink
simpledb
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Jun 24, 2024
1 parent 2f4a6cd commit 5178995
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions budgetkey_api/modules/simpledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

ROOT_DIR = Path(__file__).parent


class SimpleDBBlueprint(Blueprint):

TABLES = [
Expand Down Expand Up @@ -59,15 +60,17 @@ def process_tables(self):
ret = dict()
with self.connect_db() as connection:
for table in self.TABLES:
ret[table] = dict()
rec = ret.setdefault(table, dict())
datapackage_url = f'{self.DATAPACKAGE_URL}/{table}/datapackage.json'
package_descriptor = requests.get(datapackage_url).json()
details = package_descriptor['resources'][0]['details']
fields = package_descriptor['resources'][0]['schema']['fields']
ret['fields'] = [dict(
rec['details'] = details
rec['fields'] = [dict(
name=f['name'],
**f.get('details', {})
) for f in fields]
ret[table]['schema'] = self.get_schema(connection, table)
rec['schema'] = self.get_schema(connection, table)
return ret

def get_schema(self, connection, table):
Expand All @@ -80,7 +83,7 @@ def get_table(self, table):
if table not in self.tables:
abort(404)
return jsonpify(self.tables[table])

def get_tables(self):
return jsonpify(list(self.tables.keys()))

Expand Down

0 comments on commit 5178995

Please sign in to comment.