-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.py
More file actions
33 lines (28 loc) · 996 Bytes
/
Copy pathstorage.py
File metadata and controls
33 lines (28 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import os
class Storage:
def __init__(self):
self.file_path = "tempbox_accounts.json"
self.accounts = self._load_accounts()
def _load_accounts(self):
if os.path.exists(self.file_path):
try:
with open(self.file_path, 'r') as f:
return json.load(f)
except:
return []
return []
def save_account(self, email, password):
self.accounts.append({
"email": email,
"password": password
})
with open(self.file_path, 'w') as f:
json.dump(self.accounts, f, indent=2)
def get_accounts(self):
return self.accounts
def remove_account(self, email):
"""Remove an account from storage"""
self.accounts = [acc for acc in self.accounts if acc["email"] != email]
with open(self.file_path, 'w') as f:
json.dump(self.accounts, f, indent=2)