Spaces:
Sleeping
Sleeping
| import json | |
| import os | |
| import sys | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| import config | |
| def generate_documents(): | |
| print(f"Loading schemes from {config.SCHEMES_DB_PATH}...") | |
| with open(config.SCHEMES_DB_PATH, "r", encoding="utf-8") as f: | |
| schemes = json.load(f) | |
| os.makedirs(config.SCHEME_DOCS_PATH, exist_ok=True) | |
| for scheme in schemes: | |
| doc_content = f"""Scheme Name: {scheme['name']} ({scheme.get('name_hi', '')}) | |
| Ministry: {scheme['ministry']} | |
| Category: {scheme['category']} | |
| Launched: {scheme.get('launched', 'N/A')} | |
| Description: | |
| {scheme['description']} | |
| Benefits: | |
| - {chr(10) + '- '.join(scheme.get('benefits', []))} | |
| Eligibility Criteria: | |
| """ | |
| eligibility = scheme.get('eligibility', {}) | |
| for k, v in eligibility.items(): | |
| if v is not None: | |
| if isinstance(v, list): | |
| doc_content += f"- {k}: {', '.join(v)}\n" | |
| else: | |
| doc_content += f"- {k}: {v}\n" | |
| doc_content += f""" | |
| Application Process: | |
| {scheme.get('application_process', '')} | |
| Documents Required: | |
| - {chr(10) + '- '.join(scheme.get('documents_required', []))} | |
| Official URL: {scheme.get('official_url', 'N/A')} | |
| """ | |
| doc_path = os.path.join(config.SCHEME_DOCS_PATH, f"{scheme['id']}.txt") | |
| with open(doc_path, "w", encoding="utf-8") as out: | |
| out.write(doc_content) | |
| print(f"Generated {len(schemes)} documents in {config.SCHEME_DOCS_PATH}") | |
| if __name__ == "__main__": | |
| generate_documents() | |