def multicolumn(book, account, date1, date2): mybook = from_filename(book) account = mybook.find_account(account) if account is None: raise Exception("Cannot find account " + account) splits = [ j for j in account.splits if date1 <= j.transaction.date.date() <= date2 ] otheraccountlist = [] for split in splits: # For every transaction in this account for multisplits in split.transaction.splits: # Round up its list of accounts if multisplits.account not in otheraccountlist: # Compare with list of known accounts otheraccountlist.append( multisplits.account) # Add it to list if not known print("Date", end=",") for i in otheraccountlist: print(i.fullname(), end=",") print('Description') totals = {} for split in sorted(splits): print(split.transaction.date.date(), end=",") for j in otheraccountlist: value = sum( [i.value for i in split.transaction.splits if j == i.account]) totals[j] = totals.setdefault(j, 0) + value print(value, end=",") print(split.transaction.description) print("", end=",") for i in otheraccountlist: print(totals[i], end=",") print("Total")
def main(): text = requests.get( 'https://cotacoes.economia.uol.com.br/cambioJSONChart.html?callback=grafico.parseData&type=a&cod=BRL&mt=off' ).text rates = {} for rate in eval(text[text.find('[{"ask'):text.find(']);')]): rates[time.strftime('%Y-%m-%d', time.gmtime(rate['ts'] / 1000))] = rate['ask'] diffs = [] for transaction in gnucashxml.from_filename( '/home/marcots/gastos/gastos.gnucash').transactions: splits = transaction.splits commodity0 = splits[0].account.commodity.name commodity1 = splits[1].account.commodity.name inverse = 1.0 if commodity0 == "USD" and commodity1 == "BRL": inverse = -1.0 elif commodity0 != "BRL" or commodity1 != "USD": continue date = transaction.date.strftime('%Y-%m-%d') if date not in rates: continue diffs.append(rates[date] - (-1.0 * float(transaction.splits[0].quantity) / float(transaction.splits[1].quantity))**inverse) diffs = sorted(diffs) print(diffs[len(diffs) // 2]) print(sum(diffs) / len(diffs)) print(diffs)
def __init__(self, account_id_alpha, account_id_beta, bookfile="GNUCashLatest.gnca"): self.account_id_alpha = account_id_alpha self.account_id_beta = account_id_beta self.book = gnucashxml.from_filename(bookfile)
def main(argv): now = date.today() try: opts, args = getopt.getopt(argv, "a:b:c:") except getopt.GetoptError: print("argument error") sys.exit(2) email_user = raw_input("Gmail username: "******"Gmail password: "******"Active Members") for account in active_member_accounts.find_account("Full Members").children: member = Member(account) active_members.append(member) for account in active_member_accounts.find_account("Student Members").children: member = StudentMember(account) active_members.append(member) for member in active_members: if member.effective_balance() < 0: print(member.name(), "has a balance of", member.effective_balance(), " ", member.email()) if member.email() == None: print("ERROR:", member.name(), "does not have an email address on record") else: gmail = imaplib.IMAP4_SSL('imap.gmail.com', port = 993) gmail.login(email_user, email_pass) gmail.select('[Gmail]/Drafts') msg = email.message.Message() msg['Subject'] = 'SkullSpace Dues' msg['To'] = member.email() msg['CC'] = '*****@*****.**' msg.set_payload('Hello ' + member.name() + ',\n\nAccording to our records, your account balance is currently $' + str(member.effective_balance()) + '. Dues for the month of ' + calendar.month_name[now.month % 12 + 1] + ' were due on ' + calendar.month_name[now.month] + ' 15th. If you believe there is an issue with this record, please let us know.\n\nThank you,\n\n- Your SkullSpace Board of Directors') # extra_late_warning = "Note that since you are more than 3 months behind, you are at risk of losing your membership. Please contact us to make arrangements as soon as possible." gmail.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), str(msg))
def main(argv): try: opts, args = getopt.getopt(argv, "a:b:c:") except getopt.GetoptError: print("argument error") sys.exit(2) filename = args[0] book = gnucashxml.from_filename(filename) active_members = [] active_member_accounts = book.find_account("Active Members") for account in active_member_accounts.find_account( "Full Members").children: member = Member(account) active_members.append(member) for account in active_member_accounts.find_account( "Student Members").children: member = StudentMember(account) active_members.append(member) with open('members.csv', 'wb') as csvfile: fieldnames = [ NAME, EMAIL, MEMBERSHIP_TYPE, ACCOUNT_BALANCE, ] writer = csv.DictWriter(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames) writer.writeheader() for member in active_members: writer.writerow({ NAME: member.name(), EMAIL: member.email(), MEMBERSHIP_TYPE: member.type(), ACCOUNT_BALANCE: member.effective_balance() }) print(member.name(), "has a balance of", "$" + str(member.effective_balance()), " ", member.email()) if member.email() == None: print("ERROR:", member.name(), "does not have an email address on record")
def main(argv): try: opts, args = getopt.getopt(argv, "a:b:c:") except getopt.GetoptError: print("argument error") sys.exit(2) filename = args[0] book = gnucashxml.from_filename(filename) active_members = [] active_member_accounts = book.find_account("Active Members") for account in active_member_accounts.find_account("Full Members").children: member = Member(account) active_members.append(member) for account in active_member_accounts.find_account("Student Members").children: member = StudentMember(account) active_members.append(member) with open('members.csv', 'wb') as csvfile: fieldnames = [ NAME, EMAIL, MEMBERSHIP_TYPE, ACCOUNT_BALANCE, ] writer = csv.DictWriter(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames) writer.writeheader() for member in active_members: writer.writerow({ NAME: member.name(), EMAIL: member.email(), MEMBERSHIP_TYPE: member.type(), ACCOUNT_BALANCE: member.effective_balance() }) print(member.name(), "has a balance of", "$" + str(member.effective_balance()), " ", member.email()) if member.email() == None: print("ERROR:", member.name(), "does not have an email address on record")
def main(argv): try: opts, args = getopt.getopt(argv, "a:b:c:") except getopt.GetoptError: print("argument error") sys.exit(2) months_after = months_before = months_context = None for opt, arg in opts: if opt == '-a': months_after = int(arg) elif opt == '-b': months_before = int(arg) elif opt == '-c': months_context = int(arg) future = months_after if months_after else months_context if months_context else DEFAULT_MONTHS past = months_before if months_before else months_context if months_context else DEFAULT_MONTHS filename = args[0] book = gnucashxml.from_filename(filename) today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) if today.day + 5 < MONTH_START_DAY: today -= relativedelta(months=+1) future_delta = relativedelta(months=+future) past_delta = relativedelta(months=+past) start = today - past_delta end = today + future_delta history = [] for month in report_days(start, today): print(month) assets = get_assets_on_date(book, month) liabilities = get_liability_on_date(book, month) capital = assets + liabilities dues = get_dues_for_month(book, month) donations = get_donations_for_month(book, month) food_donations = get_food_donations_for_month(book, month) members = get_paying_members(book, month) new_members = get_new_members(book, month) lost_members = get_lost_members(book, month) donating_members = get_donating_members(book, month) expenses = get_expenses_for_month(book, month) income = get_income_for_month(book, month) food_expenses = get_food_expenses_for_month(book, month) print("Total assets: ", assets) print("Total liability: ", liabilities) print("Available capital: ", capital) print("Dues collected last month: ", dues) print("Dues paying members: ", members) print("Members gained: ", new_members) print("Members lost: ", lost_members) print("Regular donations collected last month: ", donations) print("Regularly donating members: ", donating_members) print("Food donations: ", food_donations) print("Total expected income: ", (dues + donations + food_donations)) print("Expenses: ", expenses) print("Income: ", income) print("Food expenses: ", food_expenses) history.append({ DATE: month, ASSETS: assets, LIABILITIES: liabilities, CAPITAL: capital, DUES: dues, DONATIONS: donations, FOOD_DONATIONS: food_donations, MEMBERS: members, DONATING_MEMBERS: donating_members, EXPENSES: expenses * -1, FOOD_EXPENSES: food_expenses, CAPITAL_TARGET: expenses * -3, FOOD_PROFIT: food_donations + food_expenses, NEW_MEMBERS: new_members, LOST_MEMBERS: lost_members, INCOME: income }) print() income = get_projected_income(history) income = get_historical_membership_income_average(book, start, today) expenses = get_projected_expenses( history) - get_historical_rent_expenses_average(book, start, today) print("Projected income: ", income) print("Projected expenses: ", expenses, " (plus monthly rent amount)") food_income = get_projected_food_income(history) food_expenses = get_projected_food_expenses(history) history[-1][PROJECTED_CAPITAL] = history[-1][CAPITAL] history[-1][PROJECTED_DUES] = history[-1][DUES] history[-1][PROJECTED_DONATIONS] = history[-1][DONATIONS] history[-1][PROJECTED_MEMBERS] = history[-1][MEMBERS] history[-1][PROJECTED_DONATING_MEMBERS] = history[-1][DONATING_MEMBERS] for month in report_days(today, end): print(month) history.append({ DATE: month, PROJECTED_CAPITAL: history[-1][PROJECTED_CAPITAL] + income + expenses + get_rent_expenses_for_month(book, month), PROJECTED_DUES: history[-1][PROJECTED_DUES], PROJECTED_DONATIONS: history[-1][PROJECTED_DONATIONS], PROJECTED_MEMBERS: history[-1][PROJECTED_MEMBERS], PROJECTED_DONATING_MEMBERS: history[-1][PROJECTED_DONATING_MEMBERS], PROJECTED_FOOD_DONATIONS: food_income, PROJECTED_FOOD_EXPENSES: food_expenses, CAPITAL_TARGET: (expenses + get_rent_expenses_for_month(book, month)) * -3, FOOD_PROFIT: food_income + food_expenses, }) with open('forecast.csv', 'wb') as csvfile: fieldnames = [ DATE, ASSETS, LIABILITIES, PROJECTED_CAPITAL, CAPITAL, PROJECTED_DUES, DUES, PROJECTED_DONATIONS, DONATIONS, PROJECTED_MEMBERS, MEMBERS, PROJECTED_DONATING_MEMBERS, DONATING_MEMBERS, EXPENSES, PROJECTED_FOOD_DONATIONS, FOOD_DONATIONS, PROJECTED_FOOD_EXPENSES, FOOD_EXPENSES, CAPITAL_TARGET, FOOD_PROFIT, NEW_MEMBERS, LOST_MEMBERS, INCOME, ] writer = csv.DictWriter(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames) writer.writeheader() for history_item in history: writer.writerow(history_item)
def main(self): book = gnucashxml.from_filename(self.gnucash_path) self.assets.read_assets() for transaction in book.transactions: self.read_transaction(transaction) self.table.print_table()
def main(argv): try: opts, args = getopt.getopt(argv, "a:b:c:") except getopt.GetoptError: print("argument error") sys.exit(2) months_after = months_before = months_context = None for opt, arg in opts: if opt == '-a': months_after = int(arg) elif opt == '-b': months_before = int(arg) elif opt == '-c': months_context = int(arg) future = months_after if months_after else months_context if months_context else DEFAULT_MONTHS past = months_before if months_before else months_context if months_context else DEFAULT_MONTHS filename = args[0] book = gnucashxml.from_filename(filename) today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) if today.day + 5 < MONTH_START_DAY: today -= relativedelta(months=+1) future_delta = relativedelta(months=+future) past_delta = relativedelta(months=+past) start = today - past_delta end = today + future_delta history = [] for month in report_days(start, today): print(month) assets = get_assets_on_date(book, month) liabilities = get_liability_on_date(book, month) capital = assets + liabilities dues = get_dues_for_month(book, month) donations = get_donations_for_month(book, month) food_donations = get_food_donations_for_month(book, month) members = get_paying_members(book, month) new_members = get_new_members(book, month) lost_members = get_lost_members(book, month) donating_members = get_donating_members(book, month) expenses = get_expenses_for_month(book, month) income = get_income_for_month(book, month) food_expenses = get_food_expenses_for_month(book, month) print("Total assets: ", assets) print("Total liability: ", liabilities) print("Available capital: ", capital) print("Dues collected last month: ", dues) print("Dues paying members: ", members) print("Members gained: ", new_members) print("Members lost: ", lost_members) print("Regular donations collected last month: ", donations) print("Regularly donating members: ", donating_members) print("Food donations: ", food_donations) print("Total expected income: ", (dues + donations + food_donations)) print("Expenses: ", expenses) print("Income: ", income) print("Food expenses: ", food_expenses) history.append({ DATE: month, ASSETS: assets, LIABILITIES: liabilities, CAPITAL: capital, DUES: dues, DONATIONS: donations, FOOD_DONATIONS: food_donations, MEMBERS: members, DONATING_MEMBERS: donating_members, EXPENSES: expenses * -1, FOOD_EXPENSES: food_expenses, CAPITAL_TARGET: expenses * -3, FOOD_PROFIT: food_donations + food_expenses, NEW_MEMBERS: new_members, LOST_MEMBERS: lost_members, INCOME: income }) print() income = get_projected_income(history) income = get_historical_membership_income_average(book, start, today) expenses = get_projected_expenses(history) - get_historical_rent_expenses_average(book, start, today) print("Projected income: ", income) print("Projected expenses: ", expenses, " (plus monthly rent amount)") food_income = get_projected_food_income(history) food_expenses = get_projected_food_expenses(history) history[-1][PROJECTED_CAPITAL] = history[-1][CAPITAL] history[-1][PROJECTED_DUES] = history[-1][DUES] history[-1][PROJECTED_DONATIONS] = history[-1][DONATIONS] history[-1][PROJECTED_MEMBERS] = history[-1][MEMBERS] history[-1][PROJECTED_DONATING_MEMBERS] = history[-1][DONATING_MEMBERS] for month in report_days(today, end): print(month) history.append({ DATE: month, PROJECTED_CAPITAL: history[-1][PROJECTED_CAPITAL] + income + expenses + get_rent_expenses_for_month(book, month), PROJECTED_DUES: history[-1][PROJECTED_DUES], PROJECTED_DONATIONS: history[-1][PROJECTED_DONATIONS], PROJECTED_MEMBERS: history[-1][PROJECTED_MEMBERS], PROJECTED_DONATING_MEMBERS: history[-1][PROJECTED_DONATING_MEMBERS], PROJECTED_FOOD_DONATIONS: food_income, PROJECTED_FOOD_EXPENSES: food_expenses, CAPITAL_TARGET: (expenses + get_rent_expenses_for_month(book, month)) * -3, FOOD_PROFIT: food_income + food_expenses, }) with open('forecast.csv', 'wb') as csvfile: fieldnames = [ DATE, ASSETS, LIABILITIES, PROJECTED_CAPITAL, CAPITAL, PROJECTED_DUES, DUES, PROJECTED_DONATIONS, DONATIONS, PROJECTED_MEMBERS, MEMBERS, PROJECTED_DONATING_MEMBERS, DONATING_MEMBERS, EXPENSES, PROJECTED_FOOD_DONATIONS, FOOD_DONATIONS, PROJECTED_FOOD_EXPENSES, FOOD_EXPENSES, CAPITAL_TARGET, FOOD_PROFIT, NEW_MEMBERS, LOST_MEMBERS, INCOME, ] writer = csv.DictWriter(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames) writer.writeheader() for history_item in history: writer.writerow(history_item)
import gnucashxml #filepath = '/home/rafa/Documents/6.financial/1.expense.tracking/gnucash/Data/' filepath = '/home/rafa/Documents/6.financial/1.expense.tracking/gnucash.old.for.test/Data/rp.se54.v1/' gnucashfile = 'test.rp.data.gnucash' book = gnucashxml.from_filename(filepath + gnucashfile) print(book.__repr__) income_total = 0 expense_total = 0 for account, subaccounts, splits in book.walk(): print(account.fullname()) if account.actype == 'INCOME': income_total += sum(split.value for split in account.splits) elif account.actype == 'EXPENSE': expense_total += sum(split.value for split in account.splits) print("Total income : {:9.2f}".format(income_total * -1)) print("Total expense: {:9.2f}".format(expense_total))
def main(argv): now = date.today() try: opts, args = getopt.getopt(argv, "a:b:c:") except getopt.GetoptError: print("argument error") sys.exit(2) email_user = raw_input("Gmail username: "******"Gmail password: "******"Active Members") for account in active_member_accounts.find_account( "Full Members").children: member = Member(account) active_members.append(member) for account in active_member_accounts.find_account( "Student Members").children: member = StudentMember(account) active_members.append(member) for member in active_members: if member.effective_balance() < 0: print(member.name(), "has a balance of", member.effective_balance(), " ", member.email()) if member.email() == None: print("ERROR:", member.name(), "does not have an email address on record") else: gmail = imaplib.IMAP4_SSL('imap.gmail.com', port=993) gmail.login(email_user, email_pass) gmail.select('[Gmail]/Drafts') msg = email.message.Message() msg['Subject'] = 'SkullSpace Dues' msg['To'] = member.email() msg['CC'] = '*****@*****.**' msg.set_payload( 'Hello ' + member.name() + ',\n\nAccording to our records, your account balance is currently $' + str(member.effective_balance()) + '. Dues for the month of ' + calendar.month_name[now.month % 12 + 1] + ' were due on ' + calendar.month_name[now.month] + ' 15th. If you believe there is an issue with this record, please let us know.\n\nThank you,\n\n- Your SkullSpace Board of Directors' ) # extra_late_warning = "Note that since you are more than 3 months behind, you are at risk of losing your membership. Please contact us to make arrangements as soon as possible." gmail.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), str(msg))