From 9783960857240928d909d086a931a7d553930736 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sun, 15 Sep 2024 14:22:22 -0700 Subject: [PATCH] Add some changes. I no longer know what they mean, I found them many years later. --- vanth/download.py | 6 +++-- vanth/pages/tools.py | 2 +- vanth/platform/ofxaccount.py | 1 + vanth/tables.py | 47 ++++++++++++++++++++++++++++++++++-- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/vanth/download.py b/vanth/download.py index 999d1e9..c0059cf 100644 --- a/vanth/download.py +++ b/vanth/download.py @@ -13,6 +13,8 @@ def do_all(): def transactions(source, account): body = vanth.ofx.query_transactions(source, account) - response = requests.post('https://ofx.americafirst.com/', data=body, headers={'Content-Type': 'application/x-ofx'}) + url = 'https://ofx.americafirst.com/' + response = requests.post(url, data=body, headers={'Content-Type': 'application/x-ofx'}) assert response.ok, response.text - return vanth.ofx.parse(response.text) + LOGGER.debug("Response from %s: %s %d bytes", url, response.status_code, len(response.text)) + return parse(response.text) diff --git a/vanth/pages/tools.py b/vanth/pages/tools.py index 0120a9b..b91a6f3 100644 --- a/vanth/pages/tools.py +++ b/vanth/pages/tools.py @@ -15,7 +15,7 @@ def parse(args): if supplied is None: missing_parameters.append(key) else: - values[key] = converter(supplied) + values[key] = converter(supplied) if converter else supplied if missing_parameters: return (json.dumps({'errors': [{ 'title' : "Missing required paramter '{}'".format(parameter), diff --git a/vanth/platform/ofxaccount.py b/vanth/platform/ofxaccount.py index a7aad4a..7c257ad 100644 --- a/vanth/platform/ofxaccount.py +++ b/vanth/platform/ofxaccount.py @@ -65,6 +65,7 @@ def by_user(user_id): query = query.where( vanth.tables.OFXAccount.c.owner == user_id ) + LOGGER.debug(query) return _execute_and_convert(query) def create(values): diff --git a/vanth/tables.py b/vanth/tables.py index 339621d..6f07d6d 100644 --- a/vanth/tables.py +++ b/vanth/tables.py @@ -1,6 +1,6 @@ import chryso.constants -from sqlalchemy import (Column, Date, DateTime, ForeignKey, Integer, MetaData, - Numeric, String, Table, UniqueConstraint, func, text) +from sqlalchemy import (Column, Date, DateTime, ForeignKey, Integer, + Numeric, MetaData, String, Table, UniqueConstraint, func, text) from sqlalchemy.dialects.postgresql import UUID metadata = MetaData(naming_convention=chryso.constants.CONVENTION) @@ -75,3 +75,46 @@ OFXRecord = table('ofxrecord', Column('posted', Date(), nullable=True), # The date the record posted Column('type', String(255), nullable=True), # The type of the record, like 'POS' ) + +Pool = table('pool', + Column('balance', Integer(), nullable=False), # The balance of the pool, like -10 or +12 + Column('name', String(255), nullable=False), # The name of the pool, like 'Bills' or 'Heating oil' + Column('parent', None, ForeignKey('pool.uuid', name='fk_parent'), nullable=True), + Column('user_uri', String(2048), nullable=False), # The URI of the user that created the record + UniqueConstraint('name', 'user_uri', name='pool_name_by_user') +) + +Spring = table('spring', + Column('description', String(1024), nullable=False), # A user-significant description + Column('name', String(256), nullable=False), # A user-significant name + Column('user_uri', String(2048), nullable=False), # The URI of the user that created the record + UniqueConstraint('name', 'user_uri', name='sprint_name_by_user') +) + +Sink = table('drain', + Column('description', String(1024), nullable=False), # A user-significant description + Column('name', String(256), nullable=False), # A user-significant name + Column('user_uri', String(2048), nullable=False), # The URI of the user that created the record + UniqueConstraint('name', 'user_uri', name='sink_name_by_user') +) + +Flow = table('flow', + Column('amount', Numeric(precision=20, scale=2, asdecimal=True), nullable=False), # The amount like -$177.91 + Column('description', String(1024), nullable=False), # The description that is meaningful to the user + Column('destination', None, ForeignKey(Pool.c.uuid, name='fk_destination'), nullable=True), # The pool that receives the amount + Column('source', None, ForeignKey(Pool.c.uuid, name='fk_source'), nullable=True), # The pool that originally provides the amount +) + +Inflow = table('inflow', + Column('amount', Numeric(precision=20, scale=2, asdecimal=True), nullable=False), # The amount like -$177.91 + Column('description', String(1024), nullable=False), # The description that is meaningful to the user + Column('destination', None, ForeignKey(Pool.c.uuid, name='fk_destination'), nullable=False), # The pool that receives the amount + Column('source', None, ForeignKey(Spring.c.uuid, name='fk_source'), nullable=False), # The sprint that originally provided the amount +) + +Outflow = table('outflow', + Column('amount', Numeric(precision=20, scale=2, asdecimal=True), nullable=False), # The amount like -$177.91 + Column('description', String(1024), nullable=False), # The description that is meaningful to the user + Column('destination', None, ForeignKey(Sink.c.uuid, name='fk_destination'), nullable=False), # The sink that receives the amount + Column('source', None, ForeignKey(Pool.c.uuid, name='fk_source'), nullable=False), # The pool that originally provided the amount +)