Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -35,14 +35,80 @@ def initialize_email_client():
|
|
35 |
return None
|
36 |
|
37 |
class UserProfile:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
class EmailTemplate:
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
class EmailGenie:
|
48 |
def __init__(self):
|
|
|
35 |
return None
|
36 |
|
37 |
class UserProfile:
|
38 |
+
def __init__(self):
|
39 |
+
ensure_storage_dir()
|
40 |
+
self.storage_path = os.path.join(STORAGE_DIR, 'profiles.json')
|
41 |
+
self._ensure_storage_exists()
|
42 |
+
|
43 |
+
def _ensure_storage_exists(self):
|
44 |
+
if not os.path.exists(self.storage_path):
|
45 |
+
with open(self.storage_path, 'w') as f:
|
46 |
+
json.dump({"profiles": []}, f)
|
47 |
+
|
48 |
+
def save_profile(self, profile_data: Dict) -> bool:
|
49 |
+
try:
|
50 |
+
with open(self.storage_path, 'r') as f:
|
51 |
+
data = json.load(f)
|
52 |
+
|
53 |
+
profiles = data.get("profiles", [])
|
54 |
+
profile_exists = False
|
55 |
+
for i, profile in enumerate(profiles):
|
56 |
+
if profile.get("name") == profile_data["name"]:
|
57 |
+
profiles[i] = profile_data
|
58 |
+
profile_exists = True
|
59 |
+
break
|
60 |
+
|
61 |
+
if not profile_exists:
|
62 |
+
profiles.append(profile_data)
|
63 |
+
|
64 |
+
data["profiles"] = profiles
|
65 |
+
|
66 |
+
with open(self.storage_path, 'w') as f:
|
67 |
+
json.dump(data, f)
|
68 |
+
return True
|
69 |
+
except Exception as e:
|
70 |
+
print(f"Error saving profile: {e}")
|
71 |
+
return False
|
72 |
+
|
73 |
+
def get_profile(self, name: str) -> Optional[Dict]:
|
74 |
+
try:
|
75 |
+
with open(self.storage_path, 'r') as f:
|
76 |
+
data = json.load(f)
|
77 |
+
|
78 |
+
for profile in data.get("profiles", []):
|
79 |
+
if profile.get("name") == name:
|
80 |
+
return profile
|
81 |
+
return None
|
82 |
+
except Exception as e:
|
83 |
+
print(f"Error getting profile: {e}")
|
84 |
+
return None
|
85 |
+
|
86 |
class EmailTemplate:
|
87 |
+
def __init__(self):
|
88 |
+
ensure_storage_dir()
|
89 |
+
self.templates_path = os.path.join(STORAGE_DIR, 'templates.json')
|
90 |
+
self._ensure_templates_exist()
|
91 |
+
|
92 |
+
def _ensure_templates_exist(self):
|
93 |
+
if not os.path.exists(self.templates_path):
|
94 |
+
default_templates = {
|
95 |
+
"sales_pitch": {
|
96 |
+
"subject": "Innovative Solutions for {company}",
|
97 |
+
"body": "Dear {name},\n\nI hope this email finds you well..."
|
98 |
+
},
|
99 |
+
"job_application": {
|
100 |
+
"subject": "Experienced {role} Application",
|
101 |
+
"body": "Dear {hiring_manager},\n\nI am writing to express my interest..."
|
102 |
+
}
|
103 |
+
}
|
104 |
+
with open(self.templates_path, 'w') as f:
|
105 |
+
json.dump(default_templates, f)
|
106 |
+
|
107 |
+
def get_template(self, template_name: str) -> Dict:
|
108 |
+
with open(self.templates_path, 'r') as f:
|
109 |
+
templates = json.load(f)
|
110 |
+
return templates.get(template_name, {})
|
111 |
+
|
112 |
|
113 |
class EmailGenie:
|
114 |
def __init__(self):
|