aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/elvia_gridtariff.py
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-11-09 14:11:35 +0100
committerDennis Eriksen <d@ennis.no>2023-11-09 14:11:35 +0100
commite8e33997b360bfee461d5939b7c9fef5f3de6e8c (patch)
tree8f61e55c69edbd6abf140aba462bf535c83e1f22 /scripts/elvia_gridtariff.py
parentadded new function to get env (diff)
downloadenergyscripts-e8e33997b360bfee461d5939b7c9fef5f3de6e8c.tar.gz
optimize and simplify
- use more fstrings - use exceptions - don't print "oh lol" - drop tempfiles
Diffstat (limited to 'scripts/elvia_gridtariff.py')
-rw-r--r--scripts/elvia_gridtariff.py18
1 files changed, 4 insertions, 14 deletions
diff --git a/scripts/elvia_gridtariff.py b/scripts/elvia_gridtariff.py
index 4475c48..3e8ed1e 100644
--- a/scripts/elvia_gridtariff.py
+++ b/scripts/elvia_gridtariff.py
@@ -40,30 +40,20 @@ try:
}
response = requests.post(url, headers=hdr, json=body, timeout=10)
- if response.status_code != 200:
- print(response.status_code)
- print("Oh shit")
- response.raise_for_status()
+ response.raise_for_status()
except requests.exceptions.RequestException as e:
- print("oh lol")
sys.exit(e)
data = response.json()
-print(
- "Got "
- + str(len(data["gridTariffCollections"][0]["gridTariff"]["tariffPrice"]["hours"]))
- + " items from between "
- + startTime
- + " and "
- + endTime
-)
-
+num_items = len(data["gridTariffCollections"][0]["gridTariff"]["tariffPrice"]["hours"])
+print(f"Got {num_items} items from between {startTime} and {endTime}")
### insert data into database
values = []
+
for item in data["gridTariffCollections"][0]["gridTariff"]["tariffPrice"]["hours"]:
values.append(
(