draw budget summary
This commit is contained in:
parent
ebcbe48317
commit
a9873ada47
1 changed files with 17 additions and 9 deletions
|
@ -5,26 +5,34 @@ import firefly.budgets
|
|||
|
||||
|
||||
def _get_remaining_days():
|
||||
today = datetime.date.today()
|
||||
today = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time())
|
||||
endofmonth = today.replace(day=calendar.monthrange(today.year, today.month)[1])
|
||||
return (endofmonth - today).days
|
||||
return (endofmonth - today).days + 1
|
||||
|
||||
def main():
|
||||
|
||||
def _collect_budget_data():
|
||||
budgets = []
|
||||
for budget in firefly.budgets._get_budgets():
|
||||
budgets.append({
|
||||
"id": budget.get('id'),
|
||||
"name": budget.get('attributes').get('name'),
|
||||
"limit": firefly.budgets._get_current_limit(budget.get('id')).get('attributes').get('amount'),
|
||||
"spent": str(firefly.budgets._get_current_spent_amount(budget.get('id'))),
|
||||
"spent": firefly.budgets._get_current_spent_amount(budget.get('id')),
|
||||
})
|
||||
for budget in budgets:
|
||||
remaining_per_day = (float(budget.get('limit')) - float(budget.get('spent'))) / _get_remaining_days()
|
||||
remaining_per_day = 0 if remaining_per_day < 0 else remaining_per_day
|
||||
currbudget = budgets[-1]
|
||||
currbudget['remaining'] = (float(currbudget.get('limit')) - float(currbudget.get('spent')))
|
||||
remaining_per_day = currbudget.get('remaining') / _get_remaining_days()
|
||||
currbudget['remaining_per_day'] = 0 if remaining_per_day < 0 else remaining_per_day
|
||||
return budgets
|
||||
|
||||
|
||||
def main():
|
||||
for budget in _collect_budget_data():
|
||||
print("Budget: " + budget.get('name'))
|
||||
print(" Limit: " + budget.get('limit'))
|
||||
print(" Spent: " + budget.get('spent'))
|
||||
print(" Remaining per day: " + str(remaining_per_day))
|
||||
print(" Spent: {:.2f}".format(budget.get('spent')))
|
||||
print(" Remaining: {:.2f}".format(budget.get('remaining')))
|
||||
print(" Remaining per day: {:.2f}".format(budget.get('remaining_per_day')))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue