Skip to content

Commit 215ad22

Browse files
committed
add local store only mode
1 parent fab3214 commit 215ad22

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

klimalogger/store/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from injector import Module, provider, singleton
44

55
from .client import StoreClient
6-
from .queue import QueueStore
76
from ..config import Config
87

98
log = logging.getLogger(__name__)
@@ -22,7 +21,11 @@ class StoreModule(Module):
2221
def store_provider(self, config: Config) -> StoreClient:
2322
log.info("store provider type: %s", config.store_type)
2423

25-
if config.store_type == 'queue':
24+
if config.store_type == "file":
25+
from .file import FileStore
26+
return FileStore()
27+
elif config.store_type == 'queue':
28+
from .queue import QueueStore
2629
return QueueStore(config)
2730
else:
2831
return influxdb_store_factory(config)

klimalogger/store/file.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
import os
3+
from datetime import datetime
4+
from typing import List
5+
6+
from .client import StoreClient
7+
8+
log = logging.getLogger(__name__)
9+
10+
11+
class FileStore(StoreClient):
12+
target_folder = "/var/lib/klimalogger/data"
13+
14+
def store(self, data: List[dict]):
15+
for entry in data:
16+
timestamp = datetime.fromisoformat(entry["time"])
17+
value = entry["fields"]["value"]
18+
tags = entry["tags"]
19+
measurement_type = tags["type"]
20+
unit = tags["unit"]
21+
sensor = tags["sensor"]
22+
folder_name = f"{self.target_folder}/{timestamp:%Y}/{timestamp:%m}/"
23+
file_name = f"{measurement_type}_{timestamp:%Y%m%d}.txt"
24+
25+
os.makedirs(folder_name, exist_ok=True)
26+
with open(folder_name + '/' + file_name, 'a') as output_file:
27+
output_file.write(f"{timestamp.isoformat()} {value} {unit} {sensor}\n")

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "klimalogger"
3-
version = "0.7.11"
3+
version = "0.7.12"
44
authors = [
55
{ name = "Andreas Würl", email = "andi@tryb.de" },
66
]

0 commit comments

Comments
 (0)