-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_profile.py
More file actions
50 lines (42 loc) · 1.41 KB
/
Copy pathuser_profile.py
File metadata and controls
50 lines (42 loc) · 1.41 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
import os
class UserProfile:
def __init__(self, username):
self.username = username
self.settings = {}
self.saved_actions = {}
self.load_profile()
def load_profile(self):
filename = f"{self.username}_profile.json"
if os.path.exists(filename):
with open(filename, 'r') as f:
data = json.load(f)
self.settings = data.get('settings', {})
self.saved_actions = data.get('saved_actions', {})
def save_profile(self):
filename = f"{self.username}_profile.json"
data = {
'settings': self.settings,
'saved_actions': self.saved_actions
}
with open(filename, 'w') as f:
json.dump(data, f, indent=2)
def save_action(self, name, description, steps):
self.saved_actions[name] = {
'description': description,
'steps': steps
}
self.save_profile()
def get_action(self, name):
return self.saved_actions.get(name)
def list_actions(self):
return list(self.saved_actions.keys())
def delete_action(self, name):
if name in self.saved_actions:
del self.saved_actions[name]
self.save_profile()
return True
return False
def update_settings(self, new_settings):
self.settings.update(new_settings)
self.save_profile()