Spaces:
Sleeping
Sleeping
| import os | |
| import json | |
| from datetime import datetime | |
| TEXT_DIR = os.getenv("TEXT_DIR", "text_uploads") | |
| os.makedirs(TEXT_DIR, exist_ok=True) | |
| def save_user_details(user_id: int, details: dict): | |
| """ | |
| Save user details into a text JSON file. | |
| Each user gets one file: user_<id>.json | |
| """ | |
| file_path = os.path.join(TEXT_DIR, f"user_{user_id}.json") | |
| record = { | |
| "user_id": user_id, | |
| "timestamp": datetime.utcnow().isoformat(), | |
| "details": details | |
| } | |
| with open(file_path, "w", encoding="utf-8") as f: | |
| json.dump(record, f, indent=2, ensure_ascii=False) | |
| return file_path | |
| def save_listing_details(listing_id: int, details: dict): | |
| """ | |
| Save listing details into a text JSON file. | |
| Each listing gets one file: listing_<id>.json | |
| """ | |
| file_path = os.path.join(TEXT_DIR, f"listing_{listing_id}.json") | |
| record = { | |
| "listing_id": listing_id, | |
| "timestamp": datetime.utcnow().isoformat(), | |
| "details": details | |
| } | |
| with open(file_path, "w", encoding="utf-8") as f: | |
| json.dump(record, f, indent=2, ensure_ascii=False) | |
| return file_path | |