Skip to content

Commit 7848bb4

Browse files
committed
Small improvements
* Add some error handling * Configure direnv to automaticaly activate python venv
1 parent fad2834 commit 7848bb4

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
layout python python3.10

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__pycache__
2+
.direnv
23
.env
34
.venv
45
.vscode

import_sqlite.py

100644100755
+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import datetime
23
import json
34
import sqlite3
@@ -43,6 +44,8 @@ def _check_database(con):
4344
def import_data():
4445
for account_path in _settings.storage_path.iterdir():
4546
# account_id = account_path.name
47+
if not account_path.is_dir():
48+
continue
4649

4750
for energy_meter_path in account_path.iterdir():
4851
# energy_meter = energy_meter_path.name

smartmeter.py

100644100755
+12-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import datetime
23
import json
34
import logging
@@ -135,12 +136,18 @@ def download_consumptions_for_meter(
135136
)
136137
continue
137138

138-
json_file.write_text(
139-
json.dumps(
140-
smartmeter.get_consumption_records_for_day(energy_meter, day),
141-
indent=4,
142-
)
139+
consumption_records = smartmeter.get_consumption_records_for_day(
140+
energy_meter, day
143141
)
142+
if not consumption_records["meteredValues"]:
143+
_logger.error(
144+
"Consumption records for '%s' and '%s' missing data.",
145+
energy_meter,
146+
day.isoformat(),
147+
)
148+
continue
149+
150+
json_file.write_text(json.dumps(consumption_records, indent=4))
144151

145152

146153
def main():

0 commit comments

Comments
 (0)