From f2d98d6f6a435fa0237e902897d21707b21b7d0f Mon Sep 17 00:00:00 2001 From: Robert Hirsch Date: Tue, 9 Feb 2021 13:18:00 +0100 Subject: [PATCH] setup preparation --- .gitignore | 3 +++ README.md | 4 ++-- config/__init__.py | 0 config/db_api.ini.sample | 3 +++ pyproject.toml | 6 ++++++ setup.cfg | 33 ++++++++++++++++++++++++++++++ src/controller/__init__.py | 0 src/model/__init__.py | 0 src/pybank.py | 41 +------------------------------------- 9 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 config/__init__.py create mode 100644 config/db_api.ini.sample create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 src/controller/__init__.py create mode 100644 src/model/__init__.py diff --git a/.gitignore b/.gitignore index baeacb2..08c64a5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ /database /test __pycache__/ +/build +/dist +*.egg-info !.gitignore diff --git a/README.md b/README.md index 2dc4a82..4937a27 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) +[![](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) ![CodeQL](https://github.com/hirschrobert/pybanking/workflows/CodeQL/badge.svg?branch=main) ## Alphaversion!! -## pybanking - a banking backend client at your service +## pybanking - a backend banking client at your service ### backend client for banking api (Deutsche Bank) diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/db_api.ini.sample b/config/db_api.ini.sample new file mode 100644 index 0000000..b03c68e --- /dev/null +++ b/config/db_api.ini.sample @@ -0,0 +1,3 @@ +[db_api] +client_id = put_your_client_id_here +client_secret = put_your_client_secret_here diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..374b58c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..e330820 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,33 @@ +[metadata] +name = pybanking-hirschrobert +version = 0.0.1 +url = https://github.com/hirschrobert/pybanking +author = Robert Hirsch +author_email = dev@robert-hirsch.de +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Operating System :: POSIX :: Linux +description = a backend banking client at your service +long_description = file: README.md +long_description_content_type = text/markdown + +[options] +python_requires = >=3.8 +install_requires = + beautifulsoup4>=4.8.2 + dataset>=1.4.4 + lxml>=4.5.0 + oauthlib>=3.1.0 + requests>=2.22.0 + requests-oauthlib>=1.3.0 + SQLAlchemy>=1.3.23 + urllib3>=1.25.8 +include_package_data = True +packages = find: + +[options.packages.find] +exclude=test + +[options.package_data] +config = *.ini.sample diff --git a/src/controller/__init__.py b/src/controller/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/model/__init__.py b/src/model/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pybank.py b/src/pybank.py index 32b7071..cabb9db 100644 --- a/src/pybank.py +++ b/src/pybank.py @@ -25,8 +25,7 @@ from src.controller.authorize import Authorize config = configparser.ConfigParser() -config.read('./.config/db_api.ini') # change if necessary -tokenfile = './.config/access_token.json' +config.read('./config/db_api.ini') # change if necessary client_id = config['db_api']['client_id'] client_secret = config['db_api']['client_secret'] @@ -42,44 +41,6 @@ tokenurl = 'https://simulator-api.db.com/gw/oidc/token' api = 'https://simulator-api.db.com/gw/dbapi/banking' -def init(): - oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope) - authorization_url, state = oauth.authorization_url(authorize_endpoint) - - print('Bitte diese Seite im Browser öffnen und den sechstelligen Wert von \"code\" aus der Adresszeile kopieren und hier einfügen:\n', authorization_url) - - #authorization_response = input('Bitte code eingeben: ') - - try: - authorization_response = initAuto(config) - except ValueError as err: - print(err) - return -1 - - - payload = { - 'grant_type': 'authorization_code', - 'code': authorization_response, - 'redirect_uri': redirect_uri - } - data_string = client_id + ":" + client_secret - data_bytes = data_string.encode("utf-8") - headers = { - 'Authorization': "Basic " + base64.b64encode(data_bytes).decode("utf-8"), - 'Content-Type': "application/x-www-form-urlencoded", - 'cache-control': "no-cache" - } - now = int(time.time()) - response = requests.post(tokenurl, data=payload, headers=headers) - print(response.text) - - timeadd = { 'creation_time': now} - jsonresult = json.loads(response.text) - jsonresult.update(timeadd) - with open(tokenfile, 'w') as outfile: - json.dump(jsonresult, outfile,indent=2) - return jsonresult['access_token'] - def tokenIsOutdated(creation_time,expires_in): if ((creation_time + expires_in) < int(time.time())): return True