Tidy date handling.
This commit is contained in:
parent
0eac8abea3
commit
569935a5e6
2 changed files with 6 additions and 8 deletions
|
@ -86,17 +86,17 @@ def build_parser():
|
|||
raise argparse.ArgumentTypeError(msg)
|
||||
|
||||
def previous_valid_date(s):
|
||||
return str(
|
||||
return (
|
||||
datetime.strptime(valid_date(s), "%Y-%m-%d").date() - timedelta(days=1)
|
||||
)
|
||||
).isoformat()
|
||||
|
||||
def following_valid_date(s):
|
||||
return str(
|
||||
return (
|
||||
datetime.strptime(valid_date(s), "%Y-%m-%d").date() + timedelta(days=1)
|
||||
)
|
||||
).isoformat()
|
||||
|
||||
def today():
|
||||
return str(datetime.now().date())
|
||||
return datetime.now().date().isoformat()
|
||||
|
||||
def formatter(prog):
|
||||
return argparse.HelpFormatter(prog, max_help_position=50)
|
||||
|
|
|
@ -41,14 +41,12 @@ class ECB(BaseSource):
|
|||
return [(f"EUR/{c}", f"Euro against {iso[c].name}") for c in currencies]
|
||||
|
||||
def fetch(self, series):
|
||||
almost_90_days_ago = str(datetime.now().date() - timedelta(days=85))
|
||||
almost_90_days_ago = (datetime.now().date() - timedelta(days=85)).isoformat()
|
||||
root = self._data(series.start < almost_90_days_ago)
|
||||
|
||||
all_rows = []
|
||||
for day in root.cssselect("[time]"):
|
||||
date = day.attrib["time"]
|
||||
# TODO what if it's not found for that day?
|
||||
# (some quotes aren't in the earliest data)
|
||||
for row in day.cssselect(f"[currency='{series.quote}']"):
|
||||
rate = Decimal(row.attrib["rate"])
|
||||
all_rows.insert(0, (date, rate))
|
||||
|
|
Loading…
Add table
Reference in a new issue