Spaces:
Sleeping
Sleeping
File size: 2,851 Bytes
8d3a7b6 8b45fde 8d3a7b6 8b45fde 8d3a7b6 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import json
import os
import shutil
CONTEXT_PATH = "/tmp/data/context.json"
def init_context():
if not os.path.exists("/tmp/data"):
os.makedirs("/tmp/data")
if not os.path.exists(CONTEXT_PATH):
with open(CONTEXT_PATH, "w") as f:
json.dump({"jobs": {}, "candidates": {}, 'employees': {}}, f)
def load_context():
with open(CONTEXT_PATH, "r") as f:
return json.load(f)
def save_job_context(job_id, job_data):
init_context()
context = load_context()
context["jobs"][job_id] = job_data
with open(CONTEXT_PATH, "w") as f:
json.dump(context, f, indent=2)
def save_candidate_context(candidate_id, candidate_data):
init_context()
context = load_context()
context["candidates"][candidate_id] = candidate_data
with open(CONTEXT_PATH, "w") as f:
json.dump(context, f, indent=2)
def get_job_context(job_id):
context = load_context()
return context["jobs"].get(job_id, {})
def get_candidate_context(candidate_id):
context = load_context()
return context["candidates"].get(candidate_id, {})
def get_all_jobs():
return load_context()["jobs"]
def get_all_candidates():
return load_context()["candidates"]
def save_employee_context(employee_id, employee_data):
init_context()
context = load_context()
context["employees"][employee_id] = employee_data
with open(CONTEXT_PATH, "w") as f:
json.dump(context, f, indent=2)
def get_employee_context(employee_id):
context = load_context()
return context["employees"].get(employee_id, {})
def get_all_employees():
return load_context()["employees"]
def clear_context():
"""Forcefully clears all saved job and candidate data in the context file."""
if not os.path.exists("data"):
os.makedirs("data")
with open(CONTEXT_PATH, "w") as f:
json.dump({"jobs": {}, "candidates": {}, 'employees': {}}, f, indent=2)
def save_team_summary(summary_text):
init_context()
context = load_context()
context["team_summary"] = summary_text
with open(CONTEXT_PATH, "w") as f:
json.dump(context, f, indent=2)
def get_team_summary():
context = load_context()
return context.get("team_summary", "")
def save_candidate_offer(candidate_id, offer_text):
init_context()
context = load_context()
candidate = context["candidates"].get(candidate_id, {})
if "onboarding_docs" not in candidate:
candidate["onboarding_docs"] = {}
candidate["onboarding_docs"]["offer_letter"] = offer_text
context["candidates"][candidate_id] = candidate
with open(CONTEXT_PATH, "w") as f:
json.dump(context, f, indent=2)
def get_candidate_offer(candidate_id):
context = load_context()
return context["candidates"].get(candidate_id, {}).get("onboarding_docs", {}).get("offer_letter", "")
|