mirror of
https://github.com/PaiGramTeam/EnkaNetwork.py.git
synced 2024-09-28 03:26:09 +00:00
Add config.py and move some variable to config
This commit is contained in:
parent
5b344f609f
commit
0a45919f22
31
enkanetwork/config.py
Normal file
31
enkanetwork/config.py
Normal file
@ -0,0 +1,31 @@
|
||||
from typing import (
|
||||
ClassVar
|
||||
)
|
||||
from .utils import get_user_agent
|
||||
from .cache import Cache
|
||||
|
||||
class Config:
|
||||
# HTTP Config
|
||||
ENKA_PROTOCOL: ClassVar[str] = "https"
|
||||
ENKA_URL: ClassVar[str] = "dev.enka.network"
|
||||
# Assets
|
||||
ASSETS_PROTOCOL: ClassVar[str] = "https"
|
||||
ASSETS_URL: ClassVar[str] = "raw.githubusercontent.com"
|
||||
# Header Config
|
||||
USER_AGENT: ClassVar[str] = get_user_agent()
|
||||
# Client config
|
||||
CACHE_ENABLED: ClassVar[bool] = True
|
||||
CACHE: ClassVar[Cache] = Cache(1024, 60 * 3)
|
||||
|
||||
@classmethod
|
||||
def init_cache(
|
||||
cls,
|
||||
cache: Cache,
|
||||
enabled: bool = True
|
||||
):
|
||||
cls.CACHE = cache
|
||||
cls.CACHE_ENABLED = enabled
|
||||
|
||||
@classmethod
|
||||
def init_user_agent(cls, agent: str):
|
||||
cls.USER_AGENT = agent
|
@ -66,14 +66,22 @@ def get_default_header():
|
||||
python_version = sys.version_info
|
||||
|
||||
return {
|
||||
"User-Agent": "EnkaNetwork.py/{version} (Python {major}.{minor}.{micro})".format(
|
||||
version=__version__,
|
||||
major=python_version.major,
|
||||
minor=python_version.minor,
|
||||
micro=python_version.micro
|
||||
),
|
||||
"User-Agent": get_user_agent(),
|
||||
}
|
||||
|
||||
|
||||
def get_user_agent():
|
||||
# Get python version
|
||||
python_version = sys.version_info
|
||||
|
||||
return "EnkaNetwork.py/{version} (Python {major}.{minor}.{micro})".format(
|
||||
version=__version__,
|
||||
major=python_version.major,
|
||||
minor=python_version.minor,
|
||||
micro=python_version.micro
|
||||
)
|
||||
|
||||
|
||||
class _MissingSentinel:
|
||||
__slots__ = ()
|
||||
|
||||
@ -92,6 +100,7 @@ class _MissingSentinel:
|
||||
|
||||
MISSING: Any = _MissingSentinel()
|
||||
|
||||
|
||||
async def to_data(response: ClientResponse) -> Dict[str, Any]:
|
||||
|
||||
data = bytearray()
|
||||
@ -113,4 +122,3 @@ async def to_data(response: ClientResponse) -> Dict[str, Any]:
|
||||
"content": data
|
||||
}
|
||||
return content
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user