Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the black code formatter #6

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.formatting.provider": "black"
}
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
49 changes: 26 additions & 23 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 Down Expand Up @@ -46,25 +48,25 @@ class BankSelection(Frame):

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 = [b.name for b in self.banks]
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 @@ -73,13 +75,11 @@ class BankSelection(Frame):
Error(self, e)

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 @@ -89,42 +89,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 @@ -133,4 +136,4 @@ class Error(Toplevel):

if __name__ == "__main__":
app = Application()
app.mainloop()
app.mainloop()
139 changes: 118 additions & 21 deletions 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.12b0"

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