sheerid-verify / shared_config.py
phonglanvq002's picture
Upload folder using huggingface_hub
4ac818f verified
"""
Shared Configuration Loader
Loads config from web/data/ JSON files for all verification modules.
Falls back to defaults if web config doesn't exist.
"""
import json
import os
from pathlib import Path
from typing import Dict, Any
# Path to web data directory
_WEB_DATA_DIR = Path(__file__).parent / "web" / "data"
# Default configurations (fallback if web config doesn't exist)
DEFAULT_CONFIGS = {
"gemini": {
"program_id": "67c8c14f5f17a83b745e3f82",
"sheerid_base_url": "https://services.sheerid.com",
"my_sheerid_url": "https://my.sheerid.com",
"default_school_id": "2565",
"max_file_size": 1048576,
"schools": {
"2565": {
"id": 2565,
"idExtended": "2565",
"name": "Pennsylvania State University-Main Campus",
"city": "University Park",
"state": "PA",
"country": "US",
"type": "UNIVERSITY",
"domain": "PSU.EDU"
}
}
},
"k12": {
"program_id": "68d47554aa292d20b9bec8f7",
"sheerid_base_url": "https://services.sheerid.com",
"my_sheerid_url": "https://my.sheerid.com",
"default_school_id": "3995910",
"max_file_size": 1048576,
"schools": {
"3995910": {
"id": 3995910,
"idExtended": "3995910",
"name": "Springfield High School (Springfield, OR)",
"country": "US",
"type": "HIGH_SCHOOL"
}
}
},
"spotify": {
"program_id": "67c8c14f5f17a83b745e3f82",
"sheerid_base_url": "https://services.sheerid.com",
"my_sheerid_url": "https://my.sheerid.com",
"default_school_id": "2565",
"max_file_size": 1048576,
"schools": {
"2565": {
"id": 2565,
"idExtended": "2565",
"name": "Pennsylvania State University-Main Campus",
"city": "University Park",
"state": "PA",
"country": "US",
"type": "UNIVERSITY",
"domain": "PSU.EDU"
}
}
},
"youtube": {
"program_id": "67c8c14f5f17a83b745e3f82",
"sheerid_base_url": "https://services.sheerid.com",
"my_sheerid_url": "https://my.sheerid.com",
"default_school_id": "2565",
"max_file_size": 1048576,
"schools": {
"2565": {
"id": 2565,
"idExtended": "2565",
"name": "Pennsylvania State University-Main Campus",
"city": "University Park",
"state": "PA",
"country": "US",
"type": "UNIVERSITY",
"domain": "PSU.EDU"
}
}
},
"boltnew": {
"program_id": "68cc6a2e64f55220de204448",
"sheerid_base_url": "https://services.sheerid.com",
"my_sheerid_url": "https://my.sheerid.com",
"default_school_id": "2565",
"max_file_size": 1048576,
"schools": {
"2565": {
"id": 2565,
"idExtended": "2565",
"name": "Pennsylvania State University-Main Campus",
"city": "University Park",
"state": "PA",
"country": "US",
"type": "UNIVERSITY",
"domain": "PSU.EDU"
}
}
}
}
def load_config(module_key: str) -> Dict[str, Any]:
"""Load configuration for a module from web/data/ or use defaults"""
config_file = _WEB_DATA_DIR / f"config_{module_key}.json"
if config_file.exists():
try:
with open(config_file, "r") as f:
return json.load(f)
except Exception:
pass
return DEFAULT_CONFIGS.get(module_key, {})
class ModuleConfig:
"""Dynamic config class that loads from web/data/ on attribute access"""
def __init__(self, module_key: str):
self._module_key = module_key
self._cache = None
def _load(self) -> Dict[str, Any]:
"""Load or return cached config"""
# Always reload to get latest changes
self._cache = load_config(self._module_key)
return self._cache
@property
def PROGRAM_ID(self) -> str:
return self._load().get("program_id", "")
@property
def SHEERID_BASE_URL(self) -> str:
return self._load().get("sheerid_base_url", "https://services.sheerid.com")
@property
def MY_SHEERID_URL(self) -> str:
return self._load().get("my_sheerid_url", "https://my.sheerid.com")
@property
def DEFAULT_SCHOOL_ID(self) -> str:
return self._load().get("default_school_id", "2565")
@property
def MAX_FILE_SIZE(self) -> int:
return self._load().get("max_file_size", 1048576)
@property
def SCHOOLS(self) -> Dict:
return self._load().get("schools", {})
# Pre-create config instances for each module
gemini_config = ModuleConfig("gemini")
k12_config = ModuleConfig("k12")
spotify_config = ModuleConfig("spotify")
youtube_config = ModuleConfig("youtube")
boltnew_config = ModuleConfig("boltnew")