Skip to content

Commit

Permalink
Use the black code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
adnilsson committed Oct 24, 2021
1 parent da15652 commit 7f4465c
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 156 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# Bank2YNAB4
Converts from bank transactions exported as CSV to the format accepted by YNAB4.

Expand Down
53 changes: 29 additions & 24 deletions bank2ynab.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ from src.config import BankConfig
PADX = 12
PADY = 10

BANK_DIR = Path('./banks')
BANK_DIR = Path("./banks")

###################################
# GUI-code
###################################


class Application(Tk):
"""
Main window that can repace the frame that is shown
https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter
"""

def __init__(self):
Tk.__init__(self)
self._frame = None
Expand All @@ -39,30 +41,32 @@ class Application(Tk):
class BankSelection(Frame):
def __init__(self, master=None, args=None):
Frame.__init__(self, master)
self.banks = [BankConfig.from_file(b) for b in BANK_DIR.iterdir() if b.suffix == '.toml']
self.banks = [
BankConfig.from_file(b) for b in BANK_DIR.iterdir() if b.suffix == ".toml"
]
self.createWidgets()

def createWidgets(self):
self.label = Label(self, text="Choose Your Bank:")
self.label.grid(column=0, row=0, sticky='W', ipadx=2)
self.label.grid(column=0, row=0, sticky="W", ipadx=2)

banknames = self.getNames()
self.bankName = StringVar()
self.bankName.set(banknames[0])

self.bankChosen = Combobox(self, width=12, textvariable=self.bankName)
self.bankChosen['values'] = banknames
self.bankChosen["values"] = banknames
self.bankChosen.grid(column=1, row=0)

self.confirm = Button(self, text="Ok", command=self.convert)
self.confirm.grid(column=0, row=1, columnspan=2, sticky='E', pady=5)
self.confirm.grid(column=0, row=1, columnspan=2, sticky="E", pady=5)

def convert(self):
try:
inputPath = self.getFile()
bank = self.banks[self.bankChosen.current()]
except ValueError as e:
pass # No file selected
pass # No file selected
else:
try:
result = bank2ynab(bank, inputPath)
Expand All @@ -76,13 +80,11 @@ class BankSelection(Frame):
return names

def getFile(self) -> Path:
inputPath = askopenfilename(
filetypes=[('CSV files', '*.csv')],
initialdir='.')
inputPath = askopenfilename(filetypes=[("CSV files", "*.csv")], initialdir=".")
if inputPath:
return Path(inputPath)
else:
raise ValueError('No file selected')
raise ValueError("No file selected")


class Report(Frame):
Expand All @@ -92,42 +94,45 @@ class Report(Frame):
self.createLabels(args)

self.exitButton = Button(self, text="Exit", command=self.master.destroy)
self.exitButton.grid(column=0, row=4, sticky='E')
self.exitButton.grid(column=0, row=4, sticky="E")

def createLabels(self, args):
success, blankRows, ignoredRows, linesRead, rowsParsed= args

readStats = f'{linesRead}/{linesRead+blankRows+ignoredRows} rows read'
if(blankRows+ignoredRows != 0):
ignoreStats = f' (ignored {blankRows} blank rows and ' \
f'{ignoredRows} transactions found in accignore).'
success, blankRows, ignoredRows, linesRead, rowsParsed = args

readStats = f"{linesRead}/{linesRead+blankRows+ignoredRows} rows read"
if blankRows + ignoredRows != 0:
ignoreStats = (
f" (ignored {blankRows} blank rows and "
f"{ignoredRows} transactions found in accignore)."
)
readStats = readStats + ignoreStats

parsedStats = f'{rowsParsed}/{linesRead} rows parsed '
parsedStats = f"{rowsParsed}/{linesRead} rows parsed "

if not success:
self.status = "Conversion failed."
else:
self.status = "YNAB csv-file successfully written."

self.statusLabel = Label(self, text=self.status)
self.statusLabel.grid(column=0, row=0, sticky='W', pady=5)
self.statusLabel.grid(column=0, row=0, sticky="W", pady=5)

self.readStatsLabel = Label(self, text=readStats)
self.readStatsLabel.grid(column=0, row=1, sticky='W')
self.readStatsLabel = Label(self, text=readStats)
self.readStatsLabel.grid(column=0, row=1, sticky="W")

self.parsedStatsLabel = Label(self, text=parsedStats)
self.parsedStatsLabel.grid(column=0, row=3, sticky='W')
self.parsedStatsLabel.grid(column=0, row=3, sticky="W")


class Error(Toplevel):
"""Pop-up for displaying an error message"""

def __init__(self, master, arg):
Toplevel.__init__(self, master, padx=PADX, pady=PADY)
self.title("Error")

self.msg = Message(self, text=arg, aspect=380)
self.msg.grid(column=0, row=0, pady=5)
self.msg.grid(column=0, row=0, pady=5)
self.columnconfigure(0, minsize=180)

button = Button(self, text="Dismiss", command=self.destroy)
Expand All @@ -136,4 +141,4 @@ class Error(Toplevel):

if __name__ == "__main__":
app = Application()
app.mainloop()
app.mainloop()
147 changes: 146 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tomli = "^1.2.1"
[tool.poetry.dev-dependencies]
pytest = "^6.2.4"
hypothesis = "^6.14.1"
black = "^21.9b0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
Loading

0 comments on commit 7f4465c

Please sign in to comment.