-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·39 lines (34 loc) · 1.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/env python
from pf.types.models import Account, Record, AccountStatement, init_db, _db
from pathlib import Path
import glob
from importlib import import_module
from pf.plugins.utils import log
if __name__ == "__main__":
init_db("pf.db")
dirs = glob.glob("data/*")
for d in dirs:
files = glob.glob(f"{d}/*")
name = Path(d).name
if name.startswith(".") or name.startswith("_"):
continue
import_statement = getattr(
import_module(f"pf.plugins.{name}"), "import_statement"
)
for f in files:
f = Path(f)
if AccountStatement.has_statement(f.name):
log.info(f"File '{f}' is already processed")
continue
log.info(f"Processing file '{f}'")
(acc, txns, start_date, end_date) = import_statement(f)
with _db:
Account.get_or_create(**acc)
AccountStatement.create(
fk_account_number=acc["account_number"],
start=start_date,
end=end_date,
filename=f.name,
file_content=f.read_bytes(),
)
Record.insert_many(txns).execute()