databx 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- databx-0.0.0/LICENSE +0 -0
- databx-0.0.0/PKG-INFO +5 -0
- databx-0.0.0/README.md +1 -0
- databx-0.0.0/databx/__init__.py +3 -0
- databx-0.0.0/databx/core.py +49 -0
- databx-0.0.0/databx.egg-info/PKG-INFO +5 -0
- databx-0.0.0/databx.egg-info/SOURCES.txt +9 -0
- databx-0.0.0/databx.egg-info/dependency_links.txt +1 -0
- databx-0.0.0/databx.egg-info/top_level.txt +1 -0
- databx-0.0.0/pyproject.toml +0 -0
- databx-0.0.0/setup.cfg +4 -0
databx-0.0.0/LICENSE
ADDED
|
File without changes
|
databx-0.0.0/PKG-INFO
ADDED
databx-0.0.0/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Nice Module Containing functions to save data in .json files
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DataStore:
|
|
6
|
+
def __init__(self, filename="data.json"):
|
|
7
|
+
self.filename = filename
|
|
8
|
+
self.data = []
|
|
9
|
+
self._load()
|
|
10
|
+
|
|
11
|
+
def _load(self):
|
|
12
|
+
if os.path.exists(self.filename):
|
|
13
|
+
with open(self.filename, "r", encoding="utf-8") as f:
|
|
14
|
+
try:
|
|
15
|
+
self.data = json.load(f)
|
|
16
|
+
except json.JSONDecodeError:
|
|
17
|
+
self.data = []
|
|
18
|
+
else:
|
|
19
|
+
self.data = []
|
|
20
|
+
|
|
21
|
+
def save(self, **kwargs):
|
|
22
|
+
self.data.append(kwargs)
|
|
23
|
+
with open(self.filename, "w", encoding="utf-8") as f:
|
|
24
|
+
json.dump(self.data, f, indent=4)
|
|
25
|
+
|
|
26
|
+
def load(self):
|
|
27
|
+
return self.data
|
|
28
|
+
|
|
29
|
+
def clear(self):
|
|
30
|
+
"""Löscht alle Daten."""
|
|
31
|
+
self.data = []
|
|
32
|
+
with open(self.filename, "w", encoding="utf-8") as f:
|
|
33
|
+
json.dump(self.data, f, indent=4)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ✅ Öffentliche API
|
|
37
|
+
|
|
38
|
+
def save(filename="data.json", **kwargs):
|
|
39
|
+
store = DataStore(filename)
|
|
40
|
+
store.save(**kwargs)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def load(filename="data.json"):
|
|
44
|
+
store = DataStore(filename)
|
|
45
|
+
return store.load()
|
|
46
|
+
|
|
47
|
+
def clear(filename="data.json"):
|
|
48
|
+
store = DataStore(filename)
|
|
49
|
+
store.clear()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
databx
|
|
File without changes
|
databx-0.0.0/setup.cfg
ADDED