Commits

Dan Connolly  committed b51c748

factor db_prep() out of main(); prune dead Money code

  • Participants
  • Parent commits 63c14c7

Comments (0)

Files changed (1)

File budget_sync.py

 import logging
 
 from sqlalchemy import MetaData, Table, Column
-from sqlalchemy.types import String, DECIMAL
+from sqlalchemy.types import String
 from sqlalchemy.engine.url import URL
 
 from gckey import findMaker
 
 log = logging.getLogger(__name__)
 
-Money = DECIMAL(precision=8, scale=2)
 Name = String(80)
 
 
-def main(argv, open_read, find_network_password_sync, create_engine,
-         host='localhost'):
+def main(argv, open_read, find_network_password_sync, create_engine):
     logging.basicConfig(level=logging.DEBUG)
 
     gdoc_csv, db = argv[1:3]
 
-    creds = findMaker(find_network_password_sync)(db)
+    engine = db_prepare(findMaker(find_network_password_sync),
+                        create_engine, db)
+
+    budget_load(open_read(gdoc_csv), engine)
+
+    raise NotImplementedError
+
+
+def db_prepare(findcreds, create_engine, db,
+               host='localhost'):
+    creds = findcreds(db)
 
     engine = create_engine(URL(drivername='mysql', host=host, database=db,
                                username=creds['user'],
     GnuCashAux.drop_all(engine)
     GnuCashAux.create_all(engine)
 
-    budget_load(open_read(gdoc_csv), engine)
-
-    raise NotImplementedError
+    return engine
 
 
 def budget_load(infp, conn):
                    Column('notes', String(200)))
 
 
-def money(txt):
-    '''
-    >>> money('$8,454.00')
-    (8454, 1)
-    >>> money('60')
-    (60, 1)
-    >>> money('256.69')
-    (25669, 100)
-    '''
-    try:
-        amt = int(float(txt.replace('$', '').replace(',', '')) * 100)
-    except ValueError:
-        return 0, 1
-
-    if amt % 100 == 0:
-        return amt / 100, 1
-    else:
-        return amt, 100
-
-
-def add_money((xn, xd), (yn, yd)):
-    if xd == yd:
-        return xn + yn, xd
-    else:
-        n = xn * (100 / xd) + yn * (100 / yd)
-        if n % 100 == 0:
-            return n / 100, 1
-        else:
-            return n, 100
-
-
 if __name__ == '__main__':
     def _initial_caps():
         from sys import argv