Spaces:
Sleeping
Sleeping
| import json | |
| import os | |
| import uuid | |
| from datetime import datetime | |
| import logging | |
| from hf_storage import HFStorageManager | |
| logger = logging.getLogger(__name__) | |
| class ResumeManager: | |
| def __init__(self, history_file='generated_resumes.json'): | |
| self.history_file = history_file | |
| self.storage = HFStorageManager() | |
| def _load_history(self): | |
| data = self.storage.load_file(self.history_file) | |
| if data is None: | |
| return {} | |
| if isinstance(data, dict): | |
| return data | |
| return {} | |
| def _save_history(self, history): | |
| self.storage.save_file(self.history_file, history) | |
| def get_student_resumes(self, enrollment_no): | |
| history = self._load_history() | |
| # Return list of resumes, sorted by timestamp (newest first) | |
| resumes = history.get(str(enrollment_no), []) | |
| resumes.sort(key=lambda x: x.get('timestamp', ''), reverse=True) | |
| return resumes | |
| def save_resume(self, enrollment_no, job_role, company, resume_content): | |
| history = self._load_history() | |
| enrollment_no = str(enrollment_no) | |
| if enrollment_no not in history: | |
| history[enrollment_no] = [] | |
| resume_id = str(uuid.uuid4()) | |
| timestamp = datetime.now().isoformat() | |
| # Create a title like "Software Engineer at Google" | |
| title = f"{job_role} at {company}" | |
| new_resume = { | |
| 'id': resume_id, | |
| 'title': title, | |
| 'company': company, | |
| 'role': job_role, | |
| 'timestamp': timestamp, | |
| 'content': resume_content # This will be the Markdown/HTML content | |
| } | |
| history[enrollment_no].append(new_resume) | |
| self._save_history(history) | |
| return new_resume | |
| def get_resume(self, enrollment_no, resume_id): | |
| history = self._load_history() | |
| enrollment_no = str(enrollment_no) | |
| if enrollment_no in history: | |
| for resume in history[enrollment_no]: | |
| if resume['id'] == resume_id: | |
| return resume | |
| return None | |