diff --git a/accounting/__init__.py b/accounting/__init__.py index 35910a9..ad8bf42 100644 --- a/accounting/__init__.py +++ b/accounting/__init__.py @@ -96,23 +96,23 @@ class Ledger: return output - def send_command(self, p, command): - # TODO: Should be extended to handle the locking and return the output - _bytes = p.stdin.write(command + b'\n') - p.stdin.flush() - - return _bytes - - def bal(self): + def send_command(self, command): output = None with self.locked_process() as p: - _log.debug('aquired process lock') - self.send_command(p, b'bal --format "%A|%t\\\\n"') - _log.debug('sent command') + if isinstance(command, str): + command = command.encode('utf8') + + p.stdin.write(command + b'\n') + p.stdin.flush() output = self.read_until_prompt(p) + return output + + def bal(self): + output = self.send_command('bal --format "%A|%t\\\\n"') + if output is None: raise RuntimeError('bal call returned no output') @@ -129,13 +129,7 @@ class Ledger: return accounts def reg(self): - output = None - - with self.locked_process() as p: - _log.debug('aquired process lock') - self.send_command(p, b'xml') - - output = self.read_until_prompt(p) + output = self.send_command( 'xml') if output is None: raise RuntimeError('reg call returned no output') diff --git a/accounting/web.py b/accounting/web.py index 4bc2ed7..4b15542 100644 --- a/accounting/web.py +++ b/accounting/web.py @@ -20,7 +20,7 @@ class AccountingEncoder(json.JSONEncoder): ) elif isinstance(o, Transaction): return dict( - date=o.date, + date=o.date.strftime('%Y-%m-%d'), payee=o.payee, postings=o.postings ) @@ -53,7 +53,7 @@ def register_report(): def main(): - app.run(debug=True) + app.run(host=app.config['HOST'], port=app.config['PORT']) if __name__ == '__main__': main()