add shedule by date
This commit is contained in:
parent
6b825ba85b
commit
b13a048a21
@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from os.path import dirname
|
||||
sys.path.append(dirname(__file__))
|
||||
|
||||
@ -40,5 +42,9 @@ vic = VictronShedule.VictronPriceDailyWriter(
|
||||
calculator=calc
|
||||
)
|
||||
|
||||
prices = vic.build_buy_price_schedule()
|
||||
|
||||
prices = vic.build_buy_price_schedule_by_date(datetime.now().date())
|
||||
print(prices)
|
||||
|
||||
prices = vic.build_buy_price_schedule_by_date(datetime.now().date() + timedelta(days=1))
|
||||
print(prices)
|
||||
@ -51,12 +51,9 @@ class VictronPriceDailyWriter:
|
||||
"schedule": self.build_schedule_for_day(d),
|
||||
}
|
||||
|
||||
def build_buy_price_schedule(self) -> dict[str, list[dict[str, Any]]] | None:
|
||||
today_waw = datetime.now(self.tz if hasattr(self, "tz") else WARSAW_TZ).date()
|
||||
start_date = today_waw + timedelta(days=1) # jutro
|
||||
|
||||
def build_buy_price_schedule_by_date(self, start_date:date) -> dict[str, list[dict[str, Any]]] | None:
|
||||
if not self.calculator.has_rate(local_midnight(start_date, WARSAW_TZ)):
|
||||
start_date = today_waw + timedelta(days=0)
|
||||
return None
|
||||
|
||||
blocks: List[Dict[str, Any]] = []
|
||||
single_block = self.build_buy_day_block(start_date)
|
||||
@ -66,6 +63,17 @@ class VictronPriceDailyWriter:
|
||||
return {"buyPriceSchedule": blocks}
|
||||
|
||||
|
||||
def build_buy_price_schedule(self) -> dict[str, list[dict[str, Any]]] | None:
|
||||
today_waw = datetime.now(self.tz if hasattr(self, "tz") else WARSAW_TZ).date()
|
||||
start_date = today_waw + timedelta(days=1) # jutro
|
||||
|
||||
prices = self.build_buy_price_schedule_by_date(start_date)
|
||||
if prices is None:
|
||||
start_date = today_waw + timedelta(days=0) # dziś
|
||||
|
||||
return self.build_buy_price_schedule_by_date(start_date)
|
||||
|
||||
|
||||
def build_buy_price_schedule_ending_tomorrow(self) -> dict[str, list[dict[str, Any]]] | None:
|
||||
today_waw = datetime.now(self.tz if hasattr(self, "tz") else WARSAW_TZ).date()
|
||||
end_date = today_waw + timedelta(days=0) # jutro
|
||||
|
||||
Loading…
Reference in New Issue
Block a user