Commit 403e928d authored by Jadyn Jäger's avatar Jadyn Jäger 🦄

Added experimental GUI

parent 0ede0446
......@@ -8,12 +8,14 @@ import secureStore
import sys
import getopt
import once
import cliGui
logging.basicConfig(level=100)
silent = False
def help():
print('bankingCLI by @dl6jj')
print('--password [str] / -p \t can be used to enter the password noninteractivly MAKE SURE THE COMMAND IS NOT SAVED IN .bash_history or similiar')
print('--gui \t\t\t start gui mode (default mode) (highly experimental)')
print('--password [str] / -p \t can be used to enter the password non-interactively MAKE SURE THE COMMAND IS NOT SAVED IN .bash_history or similar')
print('--silent \t\t disables text, only the requested values will be shown')
print('--account [IBAN] / -a \t set the account for the following args')
print('--accounts \t\t returns a list of your accounts (IBAN)')
......@@ -91,7 +93,7 @@ def showTransactions(iban, days):
transactions = finTS.get_transactions(account, past, today)
print_loud("The transactions from the last "+days+" days ("+account.iban+"):")
for transaction in transactions:
print(str(transaction.data['date']) + " " + str(transaction.data['amount'].amount) + " " + transaction.data['amount'].currency + "\t" + transaction.data['purpose'])
print(transaction.data['status'] + "|" + transaction.data['funds_code'] + " " +str(transaction.data['date']) + "\t" + str(transaction.data['amount'].amount) + "\t" + transaction.data['amount'].currency + "\t" + transaction.data['purpose'])
def getAccountByIBAN(iban):
accounts = finTS.get_sepa_accounts()
......@@ -126,6 +128,9 @@ def showAccountInfo(iban):
print_loud("Name:", end =" ")
print(account_info["product_name"])
def showGUI():
connectFinTS()
cliGui.main(finTS)
def print_loud(str, *args, **kwargs):
if not silent:
......@@ -133,13 +138,13 @@ def print_loud(str, *args, **kwargs):
def main(argv):
try:
opts, args = getopt.getopt(argv,"h?a:p:",["balance","transactions=","setup","help","accounts","account=", "silent", "password=", "overview", "info"])
opts, args = getopt.getopt(argv,"h?a:p:",["balance","transactions=","setup","help","accounts","account=", "silent", "password=", "overview", "info", "gui"])
except getopt.GetoptError:
help()
sys.exit(2)
sys.exit()
account = ""
if len(opts) == 0:
help()
showGUI()
for opt, arg in opts:
if opt in ("-?","-h","--help"):
help()
......@@ -165,6 +170,8 @@ def main(argv):
showTransactions(account, "30")
elif opt == "--info":
showAccountInfo(account)
elif opt == "--gui":
showGUI()
exit()
if __name__ == "__main__":
......
import curses
import datetime
import time
currentAccount = None
def define_colors(stdscr):
stdscr.clear()
stdscr.refresh()
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) # Default
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE) # Default highlighted
curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_WHITE) # Titlebar
curses.init_pair(4, curses.COLOR_RED, curses.COLOR_BLACK) # Red
curses.init_pair(5, curses.COLOR_RED, curses.COLOR_WHITE) # Red highlighted
curses.init_pair(6, curses.COLOR_GREEN, curses.COLOR_BLACK) # Green
curses.init_pair(7, curses.COLOR_GREEN, curses.COLOR_WHITE) # Green highlighted
curses.curs_set(0)
def draw_loader(stdscr):
stdscr.clear()
height, width = stdscr.getmaxyx()
title = "Loading..."
start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2)
start_y = int((height // 2) - 2)
stdscr.attron(curses.A_BOLD)
stdscr.addstr(start_y, start_x_title, title)
stdscr.refresh()
global info, accounts
info = finTS.get_information()
accounts = finTS.get_sepa_accounts()
def draw_header(stdscr):
stdscr.clear()
height, width = stdscr.getmaxyx()
if currentAccount != None:
accountName = currentAccount.iban
balance = finTS.get_balance(currentAccount)
currentBalance = str(balance.amount.amount) + " " + balance.amount.currency
else:
accountName = "?"
currentBalance = "?"
headerText = "BankingCLI by @dl6jj | {} | {} | Current balance: {}".format(info["bank"]["name"], accountName, currentBalance)
stdscr.attron(curses.color_pair(3))
stdscr.attron(curses.A_BOLD)
stdscr.addstr(0, 0, headerText)
stdscr.addstr(0, len(headerText), " " * (width - len(headerText) - 1))
stdscr.attroff(curses.color_pair(2))
stdscr.attroff(curses.A_BOLD)
def chooseAccount(stdscr):
cursor = 1
stdscr.addstr(2, 0, "Choose your account:")
height, width = stdscr.getmaxyx()
while True:
id = 1
for account in accounts:
for account_info in info["accounts"]:
if account_info["iban"] == account.iban:
accountDescription = account.iban + " " + account_info["product_name"]
if id == cursor:
stdscr.attron(curses.color_pair(2))
stdscr.addstr(id+2, 0, accountDescription)
stdscr.addstr(id+2, len(accountDescription), " " * (width - len(accountDescription) - 1))
if id == cursor:
stdscr.attroff(curses.color_pair(2))
id = id + 1
stdscr.refresh()
key = stdscr.getch()
if key == ord('q'):
exit()
elif key == curses.KEY_DOWN:
cursor = cursor + 1
elif key == curses.KEY_UP:
cursor = cursor - 1
elif key == 10:
return accounts[cursor-1]
cursor = max(1, cursor)
cursor = min(len(accounts), cursor)
def draw_transactions(stdscr):
height, width = stdscr.getmaxyx()
today = datetime.datetime.now().date()
past = today - datetime.timedelta(int(90))
transactions = finTS.get_transactions(currentAccount, past, today)
transactions.reverse()
stdscr.addstr(2, 0, "These are your last transactions")
cursor = 1
while True:
id = 1
for transaction in transactions:
if id + 3 > height:
break
colorOfset = 0
if id == cursor:
colorOfset = 1
#Red / Green if + or -
if transaction.data['amount'].amount > 0:
amount = "+"+str(transaction.data['amount'].amount)
if transaction.data['amount'].amount == 0:
amount = " "+str(transaction.data['amount'].amount)
if transaction.data['amount'].amount < 0:
amount = str(transaction.data['amount'].amount)
if transaction.data['amount'].amount < 0:
stdscr.attron(curses.color_pair(4 + colorOfset))
if transaction.data['amount'].amount > 0:
stdscr.attron(curses.color_pair(6 + colorOfset))
if transaction.data['amount'].amount == 0:
stdscr.attron(curses.color_pair(1 + colorOfset))
stdscr.addstr(id+2, 0, transaction.data['status'] + "|" + transaction.data['funds_code'] + " ")
stdscr.addstr(id+2, 4, amount)
stdscr.addstr(id+2, 4 + len(amount), " " * (13 - len(amount)))
stdscr.addstr(id+2, 13, transaction.data['amount'].currency)
stdscr.addstr(id+2, 13 + len(transaction.data['amount'].currency), " " * (18 - len(transaction.data['amount'].currency)))
stdscr.addstr(id+2, 18, str(transaction.data['date'])+ " ")
if width >= 30:
stdscr.addstr(id+2, 30, transaction.data['purpose'])
stdscr.addstr(id+2, 30 + len(transaction.data['purpose']), " " * (width - len(transaction.data['purpose']) - 31))
if transaction.data['amount'].amount < 0:
stdscr.attroff(curses.color_pair(4 + colorOfset))
if transaction.data['amount'].amount > 0:
stdscr.attroff(curses.color_pair(6 + colorOfset))
if transaction.data['amount'].amount == 0:
stdscr.attroff(curses.color_pair(1 + colorOfset))
if id == cursor:
stdscr.attroff(curses.color_pair(1))
id = id + 1
stdscr.refresh()
key = stdscr.getch()
if key == ord('q'):
exit()
elif key == curses.KEY_DOWN:
cursor = cursor + 1
elif key == curses.KEY_UP:
cursor = cursor - 1
elif key == 10:
return transactions[cursor-1]
cursor = max(1, cursor)
cursor = min(len(transactions), cursor)
def draw_transaction(stdscr, transaction):
while True:
stdscr.addstr(2, 0, "Amount:")
if transaction.data['amount'].amount > 0:
amount = "+"+str(transaction.data['amount'].amount)
if transaction.data['amount'].amount == 0:
amount = " "+str(transaction.data['amount'].amount)
if transaction.data['amount'].amount < 0:
amount = str(transaction.data['amount'].amount)
if transaction.data['amount'].amount < 0:
stdscr.attron(curses.color_pair(4))
if transaction.data['amount'].amount > 0:
stdscr.attron(curses.color_pair(6))
if transaction.data['amount'].amount == 0:
stdscr.attron(curses.color_pair(1))
stdscr.addstr(2, 25, amount + transaction.data['amount'].currency)
if transaction.data['amount'].amount < 0:
stdscr.attroff(curses.color_pair(4))
if transaction.data['amount'].amount > 0:
stdscr.attroff(curses.color_pair(6))
if transaction.data['amount'].amount == 0:
stdscr.attroff(curses.color_pair(1))
stdscr.addstr(3, 0, "Date:")
stdscr.addstr(3, 25, str(transaction.data['date']))
stdscr.addstr(4, 0, "Status:")
stdscr.addstr(4, 25, transaction.data['status'] + "|" + transaction.data['funds_code'] + " ")
stdscr.addstr(5, 0, "Type:")
stdscr.addstr(5, 25, transaction.data['posting_text'])
stdscr.addstr(6, 0, "Purpose:")
stdscr.addstr(6, 25, transaction.data['purpose'])
stdscr.addstr(7, 0, "Applicant:")
stdscr.addstr(7, 25, transaction.data['applicant_name'] + " " + transaction.data['applicant_iban'])
stdscr.addstr(8, 0, "End to end reference:")
try:
stdscr.addstr(8, 25, transaction.data['end_to_end_reference'])
except:
stdscr.addstr(8, 25, "---")
stdscr.addstr(9, 0, "Applicant creditor ID:")
try:
stdscr.addstr(9, 25, transaction.data['applicant_creditor_id'])
except:
stdscr.addstr(9, 25, "---")
stdscr.addstr(13, 0, "Press [esc] to return to the overview")
stdscr.refresh()
key = stdscr.getch()
if key == ord('q'):
exit()
elif key == 27:
return None
def draw_accountChooser(stdscr):
global currentAccount
draw_header(stdscr)
currentAccount = chooseAccount(stdscr)
def draw_overview(stdscr):
while True:
draw_header(stdscr)
transaction = draw_transactions(stdscr)
draw_header(stdscr)
draw_transaction(stdscr, transaction)
draw_loader(stdscr)
def main(bakning):
global finTS
finTS = bakning
curses.wrapper(define_colors)
curses.wrapper(draw_loader)
curses.wrapper(draw_accountChooser)
curses.wrapper(draw_loader)
curses.wrapper(draw_overview)
......@@ -3,7 +3,8 @@ A small CLI application to read your banking account balance and the last transa
## Parameters
```
--password [str] / -p can be used to enter the password noninteractivly MAKE SURE THE COMMAND IS NOT SAVED IN .bash_history or similiar
--giu starts the gui mode (default mode) (highly experimental)
--password [str] / -p can be used to enter the password non-interactively MAKE SURE THE COMMAND IS NOT SAVED IN .bash_history or similar
--silent disables text, only the requested values will be shown
--account [IBAN] / -a set the account for the following args
--accounts returns a list of your accounts (IBAN)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment