query budget data
This commit is contained in:
parent
eb005eb5c8
commit
ebcbe48317
1 changed files with 31 additions and 0 deletions
31
budgetmail.py
Normal file
31
budgetmail.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import calendar
|
||||
import datetime
|
||||
|
||||
import firefly.budgets
|
||||
|
||||
|
||||
def _get_remaining_days():
|
||||
today = datetime.date.today()
|
||||
endofmonth = today.replace(day=calendar.monthrange(today.year, today.month)[1])
|
||||
return (endofmonth - today).days
|
||||
|
||||
def main():
|
||||
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'))),
|
||||
})
|
||||
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
|
||||
print("Budget: " + budget.get('name'))
|
||||
print(" Limit: " + budget.get('limit'))
|
||||
print(" Spent: " + budget.get('spent'))
|
||||
print(" Remaining per day: " + str(remaining_per_day))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue