Skip to content

Commit

Permalink
QA: Using pre-commit package and adjusted code
Browse files Browse the repository at this point in the history
  • Loading branch information
stuertz committed Jan 8, 2020
1 parent 6f8f5e7 commit 1956e73
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: double-quote-string-fixer
- id: fix-encoding-pragma
- id: flake8
- id: mixed-line-ending
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.4.4
hooks:
- id: autopep8
# - repo: https://github.com/pre-commit/mirrors-pylint
# rev: v2.4.4
# hooks:
# - id: pylint
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.1.0
hooks:
- id: python-safety-dependencies-check
default_language_version:
python: python3.6
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Vorlagen.dat
include Vorlagen.dat
6 changes: 3 additions & 3 deletions Vorlagen.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<Steps>4</Steps>
<Filter>Text- oder CSV-Datei (*.txt;*.csv)|*.txt;*.csv</Filter>
<Description>Textbasierte Dateien, wie zum Beispiel
Daten aus Internetseiten von Banken,
können mit dieser Vorlage zum Abgleich
Daten aus Internetseiten von Banken,
können mit dieser Vorlage zum Abgleich
Ihrer onlinefähigen Konten herangezogen
werden. Beim Starten des Importvorgangs
werden. Beim Starten des Importvorgangs
öffnet sich automatisch der Online-Kontoabgleich.</Description>
<CurrencyFormat>COMMA</CurrencyFormat>
<DateFormat>TT.MM.JJJJ</DateFormat>
Expand Down
22 changes: 12 additions & 10 deletions bunqexport/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python -W ignore
# -*- coding: utf-8; mode: python -*-
# -*- coding: utf-8 -*-
"""
Connect to bunq api and create a csv file with all latest payments.
Expand All @@ -22,12 +22,12 @@

__all__ = ['main']

_log = logging.getLogger(__name__)
_log = logging.getLogger(__name__) # pylint: disable=C0103


def _setup_context(conf):
"""setup the context (login, etc) to work with bunq api"""
_log.info("Using conf: %s", conf)
_log.info('Using conf: %s', conf)
api_context = context.ApiContext.restore(conf)
api_context.ensure_session_active()
api_context.save(conf)
Expand All @@ -48,6 +48,7 @@ class Payments():
"""
Abstraction over bunq payments using a pandas dataframe
"""

def __init__(self, payments):
data = (json.loads(p.to_json()) for p in reversed(payments))
self.payments = pandas.io.json.json_normalize(data)
Expand All @@ -66,8 +67,8 @@ def __repr__(self):
index=False,
justify='left',
formatters={
'created': lambda x: x.strftime("%d.%m.%Y"),
'description': lambda x: x.replace("\n", " ").strip(),
'created': lambda x: x.strftime('%d.%m.%Y'),
'description': lambda x: x.replace('\n', ' ').strip(),
})

def to_csv(self, fname, mode):
Expand All @@ -78,13 +79,13 @@ def to_csv(self, fname, mode):
index=False, line_terminator='\r\n')
else:
self.payments.to_csv(fname, index=False)
_log.info("Wrote %s", fname)
_log.info('Wrote %s', fname)

def to_json(self, fname):
"""Create a json export from bunq data"""
fname += '.json'
self.payments.to_json(fname, orient='records', date_format='iso')
_log.info("Wrote %s", fname)
_log.info('Wrote %s', fname)

def __len__(self):
return len(self.payments)
Expand All @@ -94,6 +95,7 @@ class Balances():
"""
represent balances of of all active accounts
"""

def __init__(self):
pagination = client.Pagination()
pagination.count = 50
Expand All @@ -105,10 +107,10 @@ def __init__(self):
aacc.description: (aacc.balance.currency, aacc.balance.value)
for aacc in (monetary_account_bank
for monetary_account_bank in all_accounts
if monetary_account_bank.status == "ACTIVE")}
if monetary_account_bank.status == 'ACTIVE')}

def __repr__(self):
return "\n".join((f"{k}: {v[1]} {v[0]}"
return '\n'.join((f'{k}: {v[1]} {v[0]}'
for k, v in self.balances.items()))


Expand Down Expand Up @@ -140,7 +142,7 @@ def main():

args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO,
format="[%(levelname)-7s] %(message)s",
format='[%(levelname)-7s] %(message)s',
stream=sys.stderr)
# connect
_setup_context(args.conf)
Expand Down
10 changes: 6 additions & 4 deletions bunqexport/tests/test_exports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import datetime
# -*- coding: utf-8 -*-
"""
Tests for export.py
"""
import unittest
from .. import export
# from .. import export


class TestExports(unittest.TestCase):
# tbd
pass
"""tbd"""
24 changes: 14 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
A setuptools based setup module.
Expand All @@ -6,17 +7,17 @@
https://github.com/pypa/sampleproject
"""

# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
import codecs
import os
# Always prefer setuptools over distutils
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
HERE = os.path.abspath(os.path.dirname(__file__))

# Get the long description from the README file
with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
with codecs.open(os.path.join(HERE, 'README.md'), encoding='utf-8') as f:
LONG_DESCRIPTION = f.read()

setup(
name='bunqexport',
Expand All @@ -27,8 +28,8 @@
version='0.0.1',

description='Convert bunq payments to csv',
long_description=long_description,
long_description_content_type="text/markdown",
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',

# The project's main homepage.
url='https://github.com/stuertz/pybunqexport',
Expand Down Expand Up @@ -63,15 +64,18 @@
python_requires='>=3.6',

# Keywords related to the project
keywords='open-banking sepa bunq finance api payment csv lexware finanzmanager',
keywords=('open-banking sepa bunq finance api payment csv lexware '
'finanzmanager'),

# Packages of the project. "find_packages()" lists all the project packages.
# Packages of the project. "find_packages()" lists all the project
# packages.
packages=find_packages(exclude=['tests']),

# Run-time dependencies of the project. These will be installed by pip.
install_requires=['bunq_sdk', 'pandas'],
extras_require={
'dev': ['nose'],
'dev': ['nose', 'pre-commit', 'safety', 'flake8', 'pylint',
'autopep8'],
},
entry_points={
'console_scripts': [
Expand Down

0 comments on commit 1956e73

Please sign in to comment.