Skip to content

Commit

Permalink
fix: tempo
Browse files Browse the repository at this point in the history
  • Loading branch information
m4dm4rtig4n committed Oct 30, 2023
1 parent 5f27fc7 commit 09f2c4d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/models/query_tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from datetime import datetime

from dateutil.relativedelta import relativedelta
from dependencies import title

from config import URL
from models.query import Query
from dependencies import title
from init import DB, CONFIG
from models.query import Query


class Tempo:
Expand All @@ -18,6 +18,7 @@ def __init__(self):
self.db = DB
self.url = URL
self.valid_date = datetime.combine(datetime.now() + relativedelta(days=1), datetime.min.time())
self.nb_check_day = 31

def run(self):
start = (datetime.now() - relativedelta(years=3)).strftime("%Y-%m-%d")
Expand Down Expand Up @@ -61,8 +62,13 @@ def fetch(self):
title(f"No cache")
result = self.run()
else:
last_item = current_cache[0]
if last_item.date < self.valid_date:
valid_date = self.valid_date
missing_date = False
for i in range(self.nb_check_day):
if current_cache[i].date != valid_date:
missing_date = True
valid_date = valid_date - relativedelta(days=1)
if missing_date:
result = self.run()
else:
logging.info(" => Toutes les données sont déjà en cache.")
Expand Down

0 comments on commit 09f2c4d

Please sign in to comment.