This commit is contained in:
chris 2021-09-20 17:44:29 +02:00
parent 40cb9bb845
commit cfcf23a84d
2 changed files with 6 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import os
import calendar import calendar
import datetime import datetime
import pytz
import requests import requests
import dateutil.parser import dateutil.parser
@ -12,9 +13,10 @@ host = os.environ.get('FIREFLY_API_HOST')
def _get_budgets(): def _get_budgets():
budgets_json = requests.get( budgets_req = requests.get(
host + "/api/v1/budgets", headers=header host + "/api/v1/budgets", headers=header
).json() )
budgets_json = budgets_req.json()
budgets = budgets_json.get('data') budgets = budgets_json.get('data')
while "next" in budgets_json.get('links'): while "next" in budgets_json.get('links'):
budgets_json = requests.get( budgets_json = requests.get(
@ -35,7 +37,7 @@ def _get_current_limit(budget_id):
).json() ).json()
budgets.extend(budget_json.get('data')) budgets.extend(budget_json.get('data'))
today = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time()) today = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time()).replace(tzinfo=pytz.UTC)
return [ return [
budget for budget in budgets budget for budget in budgets
if today >= dateutil.parser.parse(budget.get('attributes').get('start')) and today <= dateutil.parser.parse(budget.get('attributes').get('end')) if today >= dateutil.parser.parse(budget.get('attributes').get('start')) and today <= dateutil.parser.parse(budget.get('attributes').get('end'))

View file

@ -1,3 +1,4 @@
Flask==1.1.2 Flask==1.1.2
python-dateutil==2.8.1 python-dateutil==2.8.1
requests==2.24.0 requests==2.24.0
pytz==2021.1