bot-config / config_manager.py
Brozy123's picture
Create config_manager.py
96d1b82 verified
Raw History Blame Contribute Delete
901 Bytes
import json
import os
from huggingface_hub import hf_hub_download, upload_file
# CHANGE THIS TO YOUR USERNAME
HF_USERNAME = "your_username_here"
REPO_NAME = "bot-config"
CONFIG_FILE = "lineup_access.json"
def load_config():
"""Load roles from cloud"""
try:
file_path = hf_hub_download(
repo_id=f"{HF_USERNAME}/{REPO_NAME}",
filename=CONFIG_FILE,
repo_type="dataset"
)
with open(file_path) as f:
return json.load(f)
except:
return {} # Return empty if first time
def save_config(data):
"""Save roles to cloud"""
# Save locally
with open(CONFIG_FILE, "w") as f:
json.dump(data, f, indent=2)
# Upload to cloud
upload_file(
path_or_fileobj=CONFIG_FILE,
path_in_repo=CONFIG_FILE,
repo_id=f"{HF_USERNAME}/{REPO_NAME}",
repo_type="dataset"
)