2024-09-15 23:12:30 -04:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from logging import Logger, getLogger
|
2024-09-17 23:24:14 -04:00
|
|
|
from sys import version as pyversion
|
2024-09-15 23:12:30 -04:00
|
|
|
from typing import Dict, List, Union
|
|
|
|
|
2024-09-15 23:18:56 -04:00
|
|
|
from pyflowery.version import VERSION
|
2024-09-15 23:12:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Voice:
|
|
|
|
"""Voice object returned from the Flowery API
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
id (str): UUID of the voice
|
|
|
|
name (str): Name of the voice
|
|
|
|
gender (str): Gender of the voice
|
|
|
|
source (str): Source of the voice
|
|
|
|
language (Language): Language object
|
|
|
|
"""
|
2024-11-15 00:10:38 -05:00
|
|
|
|
2024-09-15 23:12:30 -04:00
|
|
|
id: str
|
|
|
|
name: str
|
|
|
|
gender: str
|
|
|
|
source: str
|
2024-11-15 00:10:38 -05:00
|
|
|
language: "Language"
|
|
|
|
|
2024-09-15 23:12:30 -04:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Language:
|
|
|
|
"""Language object returned from the Flowery API
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
name (str): Name of the language
|
|
|
|
code (str): Code of the language
|
|
|
|
"""
|
2024-11-15 00:10:38 -05:00
|
|
|
|
2024-09-15 23:12:30 -04:00
|
|
|
name: str
|
|
|
|
code: str
|
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
|
2024-09-15 23:12:30 -04:00
|
|
|
@dataclass
|
|
|
|
class Result:
|
|
|
|
"""Result returned from low-level RestAdapter
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
success (bool): Boolean of whether the request was successful
|
|
|
|
status_code (int): Standard HTTP Status code
|
|
|
|
message (str = ''): Human readable result
|
2024-09-18 12:11:04 -04:00
|
|
|
data (Union[List[Dict], Dict, bytes]): Python List of Dictionaries (or maybe just a single Dictionary on error), can also be a ByteString
|
2024-09-15 23:12:30 -04:00
|
|
|
"""
|
2024-11-15 00:10:38 -05:00
|
|
|
|
2024-09-15 23:12:30 -04:00
|
|
|
success: bool
|
|
|
|
status_code: int
|
2024-11-15 00:10:38 -05:00
|
|
|
message: str = ""
|
2024-09-18 12:11:04 -04:00
|
|
|
data: Union[List[Dict], Dict, bytes] = field(default_factory=dict)
|
2024-09-15 23:12:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class FloweryAPIConfig:
|
|
|
|
"""Configuration for the Flowery API
|
|
|
|
|
|
|
|
Attributes:
|
2024-09-18 13:49:36 -04:00
|
|
|
user_agent (str): User-Agent string to use for the HTTP requests. Required as of 2.1.0.
|
2024-09-15 23:12:30 -04:00
|
|
|
logger (Logger): Logger to use for logging messages
|
2024-09-18 13:49:36 -04:00
|
|
|
allow_truncation (bool): Whether to allow truncation of text that is too long, defaults to `True`
|
|
|
|
retry_limit (int): Number of times to retry a request before giving up, defaults to `3`
|
|
|
|
interval (int): Seconds to wait between each retried request, multiplied by how many attempted requests have been made, defaults to `5`
|
2024-11-15 00:10:38 -05:00
|
|
|
|
|
|
|
Properties:
|
|
|
|
prepended_user_agent (str): The user_agent with the PyFlowery module version prepended and the Python version appended
|
2024-09-15 23:12:30 -04:00
|
|
|
"""
|
2024-11-15 00:10:38 -05:00
|
|
|
|
2024-09-18 13:49:36 -04:00
|
|
|
user_agent: str
|
2024-11-15 00:10:38 -05:00
|
|
|
logger: Logger = getLogger("pyflowery")
|
2024-09-15 23:12:30 -04:00
|
|
|
allow_truncation: bool = False
|
2024-09-17 23:24:14 -04:00
|
|
|
retry_limit: int = 3
|
|
|
|
interval: int = 5
|
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
@property
|
2024-09-17 23:24:14 -04:00
|
|
|
def prepended_user_agent(self) -> str:
|
|
|
|
"""Return the user_agent with the PyFlowery module version prepended"""
|
|
|
|
return f"PyFlowery/{VERSION} {self.user_agent} (Python {pyversion})"
|