andreped commited on
Commit
9e94231
·
1 Parent(s): 6c48ad1

Implemented Storage client

Browse files
Files changed (1) hide show
  1. postly/clients/storage_client.py +26 -0
postly/clients/storage_client.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from typing import Dict, Any
3
+
4
+
5
+ class StorageClient:
6
+ def __init__(self, file_path: str):
7
+ self.file_path = file_path
8
+ self._load_data()
9
+
10
+ def _load_data(self):
11
+ try:
12
+ with open(self.file_path, 'r') as file:
13
+ self.data = json.load(file)
14
+ except FileNotFoundError:
15
+ self.data = {"users": {}, "posts": []}
16
+
17
+ def _save_data(self):
18
+ with open(self.file_path, 'w') as file:
19
+ json.dump(self.data, file, indent=4)
20
+
21
+ def get_data(self) -> Dict[str, Any]:
22
+ return self.data
23
+
24
+ def update_data(self, data: Dict[str, Any]):
25
+ self.data = data
26
+ self._save_data()