Download modules/settings_manager.py from deanpowers/blind-monkeys: direct link, hf CLI and curl.
- Browser
- Download file 4.31 kB
-
https://huggingface.co/deanpowers/blind-monkeys/resolve/main/modules/settings_manager.py
- Command line
-
hf download hf://deanpowers/blind-monkeys/modules/settings_manager.py
-
curl -L -o settings_manager.py https://huggingface.co/deanpowers/blind-monkeys/resolve/main/modules/settings_manager.py
4.31 kB
| import os | |
| import json | |
| from config import SETTINGS_FILE, DEFAULT_SETTINGS | |
| # ---------- In-Memory Cache ---------- | |
| _settings = {} | |
| # ---------- Load Settings ---------- | |
| from modules.storage import load_json, save_json | |
| def load_settings(): | |
| """Load settings from storage or use defaults""" | |
| global _settings | |
| saved = load_json(SETTINGS_FILE, default=None) | |
| if saved is None: | |
| _settings = DEFAULT_SETTINGS.copy() | |
| save_settings() | |
| print("Created default settings in storage") | |
| else: | |
| _settings = {**DEFAULT_SETTINGS, **saved} | |
| if not isinstance(_settings.get('excluded_coins'), list): | |
| _settings['excluded_coins'] = [] | |
| print("Loaded settings from storage") | |
| return _settings | |
| def save_settings(): | |
| """Save current settings to storage""" | |
| return save_json(SETTINGS_FILE, _settings) | |
| # ---------- Get Settings ---------- | |
| def get_settings(): | |
| """Get current settings""" | |
| if not _settings: | |
| load_settings() | |
| return _settings.copy() | |
| # ---------- Update Settings ---------- | |
| def update_settings(new_settings): | |
| """Update settings with validation for each type""" | |
| global _settings | |
| if not _settings: | |
| load_settings() | |
| validated = {} | |
| for key, value in new_settings.items(): | |
| if key not in DEFAULT_SETTINGS: | |
| continue | |
| # Handle excluded_coins (list of strings) | |
| if key == 'excluded_coins': | |
| if isinstance(value, list): | |
| validated[key] = [str(c) for c in value] | |
| continue | |
| # Handle auto_filter_bingx (boolean flag) | |
| if key == 'auto_filter_bingx': | |
| validated[key] = 1 if value else 0 | |
| continue | |
| # Handle numeric settings | |
| try: | |
| validated[key] = int(float(value)) | |
| except (ValueError, TypeError): | |
| print(f"⚠️ Invalid value for {key}: {value}, skipping") | |
| _settings.update(validated) | |
| save_settings() | |
| print(f"✅ Settings updated: {list(validated.keys())}") | |
| return _settings.copy() | |
| # ---------- Reset Settings ---------- | |
| def reset_settings(): | |
| """Reset settings to defaults (preserves excluded_coins)""" | |
| global _settings | |
| if not _settings: | |
| load_settings() | |
| excluded = _settings.get('excluded_coins', []) | |
| _settings = {**DEFAULT_SETTINGS, "excluded_coins": excluded} | |
| save_settings() | |
| print("✅ Settings reset to defaults (exclusions preserved)") | |
| return _settings.copy() | |
| # ---------- Individual Getters ---------- | |
| def get_scan_min_market_cap(): | |
| return get_settings().get("scan_min_market_cap", DEFAULT_SETTINGS["scan_min_market_cap"]) | |
| def get_scan_min_volume(): | |
| return get_settings().get("scan_min_volume", DEFAULT_SETTINGS["scan_min_volume"]) | |
| def get_scan_max_coins(): | |
| return get_settings().get("scan_max_coins", DEFAULT_SETTINGS["scan_max_coins"]) | |
| def get_cache_ttl_hours(): | |
| return get_settings().get("coin_cache_ttl_hours", DEFAULT_SETTINGS["coin_cache_ttl_hours"]) | |
| def get_auto_filter_bingx(): | |
| """Check if auto-filter by BingX availability is enabled""" | |
| return bool(get_settings().get("auto_filter_bingx", 1)) | |
| def get_excluded_coins(): | |
| """Get the list of excluded coin IDs""" | |
| return get_settings().get("excluded_coins", []) | |
| def add_excluded_coin(coin_id): | |
| """Add a coin to the exclusion list""" | |
| global _settings | |
| if not _settings: | |
| load_settings() | |
| excluded = _settings.get('excluded_coins', []) | |
| if coin_id not in excluded: | |
| excluded.append(coin_id) | |
| _settings['excluded_coins'] = excluded | |
| save_settings() | |
| return True | |
| return False | |
| def remove_excluded_coin(coin_id): | |
| """Remove a coin from the exclusion list""" | |
| global _settings | |
| if not _settings: | |
| load_settings() | |
| excluded = _settings.get('excluded_coins', []) | |
| if coin_id in excluded: | |
| excluded.remove(coin_id) | |
| _settings['excluded_coins'] = excluded | |
| save_settings() | |
| return True | |
| return False | |
| def set_excluded_coins(coin_ids): | |
| """Replace the entire exclusion list""" | |
| global _settings | |
| if not _settings: | |
| load_settings() | |
| _settings['excluded_coins'] = [str(c) for c in coin_ids] | |
| save_settings() | |
| return _settings['excluded_coins'] | |