move helpers
This commit is contained in:
parent
4a1eccc3a2
commit
340ff5270e
2 changed files with 32 additions and 0 deletions
|
@ -0,0 +1,14 @@
|
||||||
|
"""Firefly3 API modules"""
|
||||||
|
import datetime
|
||||||
|
import calendar
|
||||||
|
|
||||||
|
|
||||||
|
def get_remaining_days():
|
||||||
|
"""Get number of days remaining in current month"""
|
||||||
|
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 + 1
|
|
@ -6,6 +6,8 @@ import datetime
|
||||||
import requests
|
import requests
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
|
||||||
|
import firefly
|
||||||
|
|
||||||
|
|
||||||
header = {"Authorization": "Bearer " + os.environ.get('FIREFLY_PERSONAL_ACCESS_TOKEN')}
|
header = {"Authorization": "Bearer " + os.environ.get('FIREFLY_PERSONAL_ACCESS_TOKEN')}
|
||||||
host = os.environ.get('FIREFLY_API_HOST')
|
host = os.environ.get('FIREFLY_API_HOST')
|
||||||
|
@ -70,6 +72,22 @@ def _get_current_spent_amount(budget_id):
|
||||||
return spent_amount
|
return spent_amount
|
||||||
|
|
||||||
|
|
||||||
|
def _collect_budget_data():
|
||||||
|
budgets = []
|
||||||
|
for budget in _get_budgets():
|
||||||
|
budgets.append({
|
||||||
|
"id": budget.get('id'),
|
||||||
|
"name": budget.get('attributes').get('name'),
|
||||||
|
"limit": _get_current_limit(budget.get('id')).get('attributes').get('amount'),
|
||||||
|
"spent": _get_current_spent_amount(budget.get('id')),
|
||||||
|
})
|
||||||
|
currbudget = budgets[-1]
|
||||||
|
currbudget['remaining'] = (float(currbudget.get('limit')) - float(currbudget.get('spent')))
|
||||||
|
remaining_per_day = currbudget.get('remaining') / firefly.get_remaining_days()
|
||||||
|
currbudget['remaining_per_day'] = 0 if remaining_per_day < 0 else remaining_per_day
|
||||||
|
return budgets
|
||||||
|
|
||||||
|
|
||||||
def get_budget_metrics():
|
def get_budget_metrics():
|
||||||
out = ""
|
out = ""
|
||||||
for budget in _get_budgets():
|
for budget in _get_budgets():
|
||||||
|
|
Loading…
Reference in a new issue