Created
December 15, 2024 17:11
-
-
Save Meatballs1/0858325c70016def4c26fafa0a1b4f99 to your computer and use it in GitHub Desktop.
Agile Price Batpred yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from OctopusAgile import Agile | |
import datetime | |
import yaml | |
today = datetime.date.today() | |
agile = Agile('B') # N is the region code for Southern Scotland | |
date_from = today + datetime.timedelta(days=1) | |
date_to = today + datetime.timedelta(days=2) | |
rates = agile.get_rates(date_from, date_to) | |
date = (today + datetime.timedelta(days=1)).strftime("%Y-%m-%d") | |
rates_formatted = [] | |
for time, rate in rates['date_rates'].items(): | |
time = datetime.datetime.strptime(time, "%Y-%m-%dT%H:%M:%SZ") | |
start = time.strftime("%H:%M:%S") | |
end = (time + datetime.timedelta(minutes=30)).strftime("%H:%M:%S") | |
rates_formatted.append({"date":date, "start":start, "end":end, "rate":rate}) | |
output = { "rates_import_override":rates_formatted } | |
print(yaml.dump(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment