mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-05-28 22:29:27 +03:00
Added util method for URL -> KillSwitchSet
This commit is contained in:
parent
f7890a460b
commit
29adaa413b
@ -1,4 +1,5 @@
|
||||
"""Fetch kill switches from EDMC Repo."""
|
||||
from ast import parse
|
||||
from typing import Dict, List, NamedTuple, Optional, Union, cast
|
||||
|
||||
import requests
|
||||
@ -49,7 +50,7 @@ class KillSwitchSet:
|
||||
return f'KillSwitchSet: {str(self.kill_switches)}'
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""return __repr__ for KillSwitchSet."""
|
||||
"""Return __repr__ for KillSwitchSet."""
|
||||
return f'KillSwitchSet(kill_switches={self.kill_switches!r})'
|
||||
|
||||
|
||||
@ -117,6 +118,20 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]:
|
||||
return out
|
||||
|
||||
|
||||
def get_kill_switches(target=DEFAULT_KILLSWITCH_URL) -> Optional[KillSwitchSet]:
|
||||
"""
|
||||
Get a kill switch set object.
|
||||
|
||||
:param target: the URL to fetch the killswitch JSON from, defaults to DEFAULT_KILLSWITCH_URL
|
||||
:return: the KillSwitchSet for the URL, or None if there was an error
|
||||
"""
|
||||
if (data := fetch_kill_switches(target)) is None:
|
||||
logger.warning('could not get killswitches')
|
||||
return None
|
||||
|
||||
return KillSwitchSet(parse_kill_switches(data))
|
||||
|
||||
|
||||
active: KillSwitchSet = KillSwitchSet([])
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user