Skip to content

Commit 2d88a33

Browse files
authored
Merge pull request #2 from shinxz12/develop
feat: add banks data by using VietQR API
2 parents b6e4f6e + f8719ed commit 2d88a33

File tree

6 files changed

+102
-218
lines changed

6 files changed

+102
-218
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ ENV/
112112

113113
# mkdocs build dir
114114
site/
115+
116+
# banks data
117+
resources/banks.json

.pre-commit-config.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ repos:
1818
- id: isort
1919
args: [ "--filter-files" ]
2020
- repo: https://github.com/ambv/black
21-
rev: 22.3.0
21+
rev: 24.2.0
2222
hooks:
2323
- id: black
2424
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v0.901
25+
rev: v1.9.0
2626
hooks:
2727
- id: mypy
2828
exclude: tests/
2929
additional_dependencies:
3030
- types-click
31+
- types-requests

poetry.lock

+57-206
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ classifiers=[
1313
'License :: OSI Approved :: MIT License',
1414
'Natural Language :: English',
1515
'Programming Language :: Python :: 3',
16-
'Programming Language :: Python :: 3.7',
1716
'Programming Language :: Python :: 3.8',
1817
'Programming Language :: Python :: 3.9',
1918
'Programming Language :: Python :: 3.10',
@@ -26,14 +25,15 @@ packages = [
2625
]
2726

2827
[tool.poetry.dependencies]
29-
python = ">=3.7.2,<4.0"
30-
click = "8.0.1"
28+
python = ">=3.8.2,<4.0"
29+
segno = "^1.6.1"
30+
requests = "^2.31.0"
3131

32-
black = { version = "^21.5b2", optional = true}
32+
black = { version = "^22.3.0", optional = true}
3333
isort = { version = "^5.8.0", optional = true}
3434
flake8 = { version = "^3.9.2", optional = true}
3535
flake8-docstrings = { version = "^1.6.0", optional = true }
36-
mypy = {version = "^0.900", optional = true}
36+
mypy = {version = "^1.9.0", optional = true}
3737
pytest = { version = "^6.2.4", optional = true}
3838
pytest-cov = { version = "^2.12.0", optional = true}
3939
tox = { version = "^3.20.1", optional = true}
@@ -49,7 +49,7 @@ mkdocs-autorefs = {version = "^0.2.1", optional = true}
4949
pre-commit = {version = "^2.12.0", optional = true}
5050
toml = {version = "^0.10.2", optional = true}
5151
bump2version = {version = "^1.0.1", optional = true}
52-
segno = "^1.6.1"
52+
types-requests = {version = "^2.31.0.20240311", optional = true}
5353

5454
[tool.poetry.extras]
5555
test = [
@@ -79,7 +79,7 @@ napas_qr = 'qr_pay.cli:main'
7979
[tool.black]
8080
line-length = 120
8181
skip-string-normalization = true
82-
target-version = ['py36', 'py37', 'py38']
82+
target-version = ['py38', 'py39', 'py310', 'py311']
8383
include = '\.pyi?$'
8484
exclude = '''
8585
/(

qr_pay/utils.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
from typing import List, Optional
3+
4+
import requests
5+
6+
7+
class Bank:
8+
def __init__(self) -> None:
9+
self.banks = self.get_banks()
10+
11+
def update_banks(self) -> List[dict]:
12+
url = "https://api.vietqr.io/v2/banks"
13+
response = requests.get(url)
14+
response.raise_for_status()
15+
data = response.json()["data"]
16+
with open("./resources/banks.json", "w") as file:
17+
json.dump(data, file)
18+
self.banks = data
19+
return data
20+
21+
def get_banks(self) -> List[dict]:
22+
try:
23+
with open("./resources/banks.json", "r") as file:
24+
data = json.load(file)
25+
return data
26+
except:
27+
return self.update_banks()
28+
29+
def get_bank_by_code(self, code: str) -> Optional[dict]:
30+
result = list(filter(lambda x: x["code"] == code.upper(), self.banks))
31+
return result[0] if result else None

setup.cfg

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exclude_lines =
4040

4141
[tox:tox]
4242
isolated_build = true
43-
envlist = py36, py37, py38, py39, py310, py311, py312, format, lint
43+
envlist = py38, py39, py310, py311, py312, format, lint
4444

4545
[gh-actions]
4646
python =
@@ -49,8 +49,6 @@ python =
4949
3.10: py310
5050
3.9: py39
5151
3.8: py38, format, lint, build
52-
3.7: py37
53-
3.6: py36
5452

5553
[testenv]
5654
allowlist_externals = pytest

0 commit comments

Comments
 (0)