diff --git a/solvedac_community/HTTPClients/abstract_http_client.py b/solvedac_community/HTTPClients/abstract_http_client.py index 62a9462..e124fa7 100644 --- a/solvedac_community/HTTPClients/abstract_http_client.py +++ b/solvedac_community/HTTPClients/abstract_http_client.py @@ -16,7 +16,7 @@ from abc import ABCMeta, abstractmethod from typing import Optional, Dict -from .httpclient import ResponseData, Route +from solvedac_community.HTTPClients.httpclient import ResponseData, Route class AbstractHTTPClient(metaclass=ABCMeta): diff --git a/solvedac_community/HTTPClients/aiohttp_client.py b/solvedac_community/HTTPClients/aiohttp_client.py index 69b2a59..89005ea 100644 --- a/solvedac_community/HTTPClients/aiohttp_client.py +++ b/solvedac_community/HTTPClients/aiohttp_client.py @@ -19,8 +19,8 @@ import aiohttp -from .abstract_http_client import AbstractHTTPClient -from .httpclient import MISSING, ResponseData, Route +from solvedac_community.HTTPClients.abstract_http_client import AbstractHTTPClient +from solvedac_community.HTTPClients.httpclient import MISSING, ResponseData, Route class AiohttpHTTPClient(AbstractHTTPClient): diff --git a/solvedac_community/HTTPClients/httpclient.py b/solvedac_community/HTTPClients/httpclient.py index 76c0c62..dba7fee 100644 --- a/solvedac_community/HTTPClients/httpclient.py +++ b/solvedac_community/HTTPClients/httpclient.py @@ -36,7 +36,7 @@ def get_http_client( if lib is None: try: import aiohttp - from .aiohttp_client import AiohttpHTTPClient + from solvedac_community.HTTPClients.aiohttp_client import AiohttpHTTPClient return AiohttpHTTPClient(loop, solvedac_token) except ImportError: @@ -44,7 +44,7 @@ def get_http_client( try: import httpx - from .httpx_client import HttpxHTTPClient + from solvedac_community.HTTPClients.httpx_client import HttpxHTTPClient return HttpxHTTPClient(loop, solvedac_token) except ImportError: @@ -53,12 +53,12 @@ def get_http_client( raise ImportError("At least one of aiohttp or httpx libraries is required") if lib == HTTPClientLibrary.HTTPX: - from .httpx_client import HttpxHTTPClient + from solvedac_community.HTTPClients.httpx_client import HttpxHTTPClient return HttpxHTTPClient(loop, solvedac_token) elif lib == HTTPClientLibrary.AIOHTTP: - from .aiohttp_client import AiohttpHTTPClient + from solvedac_community.HTTPClients.aiohttp_client import AiohttpHTTPClient return AiohttpHTTPClient(loop, solvedac_token) diff --git a/solvedac_community/HTTPClients/httpx_client.py b/solvedac_community/HTTPClients/httpx_client.py index 42e602a..8ec520a 100644 --- a/solvedac_community/HTTPClients/httpx_client.py +++ b/solvedac_community/HTTPClients/httpx_client.py @@ -18,8 +18,8 @@ import httpx -from .abstract_http_client import AbstractHTTPClient -from .httpclient import ResponseData, Route +from solvedac_community.HTTPClients.abstract_http_client import AbstractHTTPClient +from solvedac_community.HTTPClients.httpclient import ResponseData, Route class HttpxHTTPClient(AbstractHTTPClient): diff --git a/solvedac_community/Schemas/Enums/__init__.py b/solvedac_community/Schemas/Enums/__init__.py new file mode 100644 index 0000000..a9cb085 --- /dev/null +++ b/solvedac_community/Schemas/Enums/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from .badge_category import BadgeCategory +from .badge_tier import BadgeTier +from .class_decoration import ClassDecoration +from .price_unit import PriceUnit +from .problem_level import ProblemLevel +from .sort_direction import SortDirection +from .sort_type import SortType +from .user_tier import UserTier diff --git a/solvedac_community/Models/badge_category.py b/solvedac_community/Schemas/Enums/badge_category.py similarity index 100% rename from solvedac_community/Models/badge_category.py rename to solvedac_community/Schemas/Enums/badge_category.py diff --git a/solvedac_community/Models/badge_tier.py b/solvedac_community/Schemas/Enums/badge_tier.py similarity index 100% rename from solvedac_community/Models/badge_tier.py rename to solvedac_community/Schemas/Enums/badge_tier.py diff --git a/solvedac_community/Models/class_decoration.py b/solvedac_community/Schemas/Enums/class_decoration.py similarity index 100% rename from solvedac_community/Models/class_decoration.py rename to solvedac_community/Schemas/Enums/class_decoration.py diff --git a/solvedac_community/Models/price_unit.py b/solvedac_community/Schemas/Enums/price_unit.py similarity index 100% rename from solvedac_community/Models/price_unit.py rename to solvedac_community/Schemas/Enums/price_unit.py diff --git a/solvedac_community/Models/problem_level.py b/solvedac_community/Schemas/Enums/problem_level.py similarity index 100% rename from solvedac_community/Models/problem_level.py rename to solvedac_community/Schemas/Enums/problem_level.py diff --git a/solvedac_community/Models/sort_direction.py b/solvedac_community/Schemas/Enums/sort_direction.py similarity index 100% rename from solvedac_community/Models/sort_direction.py rename to solvedac_community/Schemas/Enums/sort_direction.py diff --git a/solvedac_community/Models/sort_type.py b/solvedac_community/Schemas/Enums/sort_type.py similarity index 100% rename from solvedac_community/Models/sort_type.py rename to solvedac_community/Schemas/Enums/sort_type.py diff --git a/solvedac_community/Models/user_tier.py b/solvedac_community/Schemas/Enums/user_tier.py similarity index 100% rename from solvedac_community/Models/user_tier.py rename to solvedac_community/Schemas/Enums/user_tier.py diff --git a/solvedac_community/Models/__init__.py b/solvedac_community/Schemas/Models/__init__.py similarity index 90% rename from solvedac_community/Models/__init__.py rename to solvedac_community/Schemas/Models/__init__.py index 991fa76..2a04280 100644 --- a/solvedac_community/Models/__init__.py +++ b/solvedac_community/Schemas/Models/__init__.py @@ -13,19 +13,16 @@ OTHER DEALINGS IN THE SOFTWARE. """ +from .account_info import AccountInfo from .author import Author from .auto_completion_data import AutoCompletionData from .background import Background from .badge import Badge from .coinshop_product import CoinshopProduct from .organization import Organization -from .problem_level import ProblemLevel from .problem_level_data import ProblemLevelData from .problem_search_data import ProblemSearchData from .problem_stats import ProblemStats from .solvedac_statistics import SolvedAcStatistics -from .sort_direction import SortDirection -from .sort_type import SortType from .tagged_problem import TaggedProblem from .user import User -from .account_info import AccountInfo diff --git a/solvedac_community/Models/account_info.py b/solvedac_community/Schemas/Models/account_info.py similarity index 73% rename from solvedac_community/Models/account_info.py rename to solvedac_community/Schemas/Models/account_info.py index 0d04729..3ef7aa1 100644 --- a/solvedac_community/Models/account_info.py +++ b/solvedac_community/Schemas/Models/account_info.py @@ -13,27 +13,14 @@ OTHER DEALINGS IN THE SOFTWARE. """ -from datetime import datetime from dataclasses import dataclass -from .auto_completion_data import SimplifiedUser -from .settings import Settings -from ..utils import get_datetime_from_string - +from datetime import datetime from typing import Dict, Union, List - -@dataclass -class EmoticonInfo: - emoticon_id: str - emoticon_url: str - display_name: str - unlocked: bool - - def __init__(self, data: Dict[str, Union[str, bool]]): - self.emoticon_id = data["emoticonId"] - self.emoticon_url = data["emoticonUrl"] - self.display_name = data["displayName"] - self.unlocked = data["unlocked"] +from solvedac_community.Schemas.Models.auto_completion_data import SimplifiedUser +from solvedac_community.Schemas.Models.emoticon_info import EmoticonInfo +from solvedac_community.Schemas.Models.settings import Settings +from solvedac_community.utils import get_datetime_from_string @dataclass diff --git a/solvedac_community/Models/author.py b/solvedac_community/Schemas/Models/author.py similarity index 100% rename from solvedac_community/Models/author.py rename to solvedac_community/Schemas/Models/author.py diff --git a/solvedac_community/Schemas/Models/auto_complete_text.py b/solvedac_community/Schemas/Models/auto_complete_text.py new file mode 100644 index 0000000..dfc97e4 --- /dev/null +++ b/solvedac_community/Schemas/Models/auto_complete_text.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from dataclasses import dataclass +from typing import Dict + + +@dataclass() +class AutoCompleteText: + caption: str + description: str + + def __init__(self, data: Dict[str, str]): + self.caption: str = data["caption"] + self.description: str = data["description"] diff --git a/solvedac_community/Schemas/Models/auto_completion_data.py b/solvedac_community/Schemas/Models/auto_completion_data.py new file mode 100644 index 0000000..04ffc21 --- /dev/null +++ b/solvedac_community/Schemas/Models/auto_completion_data.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from dataclasses import dataclass +from typing import Dict, Union, List + +from solvedac_community.Schemas.Models.auto_complete_text import AutoCompleteText +from solvedac_community.Schemas.Models.simplified_problem import SimplifiedProblem +from solvedac_community.Schemas.Models.simplified_tag import SimplifiedTag +from solvedac_community.Schemas.Models.simplified_user import SimplifiedUser + + +@dataclass +class AutoCompletionData: + autocomplete: List[AutoCompleteText] + problems: List[SimplifiedProblem] + problem_count: int + tags: List[SimplifiedTag] + tag_count: int + users: List[SimplifiedUser] + user_count: int + + def __init__(self, data: Dict[str, Union[list, int]]): + self.autocomplete: List[AutoCompleteText] = [AutoCompleteText(dat) for dat in data["autocomplete"]] + self.problems: List[SimplifiedProblem] = [SimplifiedProblem(dat) for dat in data["problems"]] + self.problem_count: int = data["problemCount"] + self.tags: List[SimplifiedTag] = [SimplifiedTag(dat) for dat in data["tags"]] + self.tag_count: int = data["tagCount"] + self.users: List[SimplifiedUser] = [SimplifiedUser(dat) for dat in data["users"]] + self.user_count: int = data["userCount"] diff --git a/solvedac_community/Models/background.py b/solvedac_community/Schemas/Models/background.py similarity index 94% rename from solvedac_community/Models/background.py rename to solvedac_community/Schemas/Models/background.py index 50396e0..cadeec6 100644 --- a/solvedac_community/Models/background.py +++ b/solvedac_community/Schemas/Models/background.py @@ -14,9 +14,9 @@ """ from dataclasses import dataclass -from typing import Dict, Union, Optional, List +from typing import Dict, Union, List -from .author import Author +from solvedac_community.Schemas.Models.author import Author @dataclass() diff --git a/solvedac_community/Models/badge.py b/solvedac_community/Schemas/Models/badge.py similarity index 89% rename from solvedac_community/Models/badge.py rename to solvedac_community/Schemas/Models/badge.py index 0f6d813..4d1ac0b 100644 --- a/solvedac_community/Models/badge.py +++ b/solvedac_community/Schemas/Models/badge.py @@ -16,8 +16,8 @@ from dataclasses import dataclass from typing import Dict -from .badge_tier import BadgeTier -from .badge_category import BadgeCategory +from solvedac_community.Schemas.Enums.badge_category import BadgeCategory +from solvedac_community.Schemas.Enums.badge_tier import BadgeTier @dataclass diff --git a/solvedac_community/Models/coinshop_product.py b/solvedac_community/Schemas/Models/coinshop_product.py similarity index 88% rename from solvedac_community/Models/coinshop_product.py rename to solvedac_community/Schemas/Models/coinshop_product.py index f5c4af7..b35f792 100644 --- a/solvedac_community/Models/coinshop_product.py +++ b/solvedac_community/Schemas/Models/coinshop_product.py @@ -14,10 +14,10 @@ """ from dataclasses import dataclass -from typing import Dict, Optional, Union +from typing import Dict, Union -from .item import Item -from .price_unit import PriceUnit +from solvedac_community.Schemas.Enums.price_unit import PriceUnit +from solvedac_community.Schemas.Models.item import Item @dataclass() diff --git a/solvedac_community/Schemas/Models/emoticon_info.py b/solvedac_community/Schemas/Models/emoticon_info.py new file mode 100644 index 0000000..d69a3a5 --- /dev/null +++ b/solvedac_community/Schemas/Models/emoticon_info.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from dataclasses import dataclass +from typing import Dict, Union + + +@dataclass +class EmoticonInfo: + emoticon_id: str + emoticon_url: str + display_name: str + unlocked: bool + + def __init__(self, data: Dict[str, Union[str, bool]]): + self.emoticon_id = data["emoticonId"] + self.emoticon_url = data["emoticonUrl"] + self.display_name = data["displayName"] + self.unlocked = data["unlocked"] diff --git a/solvedac_community/Models/item.py b/solvedac_community/Schemas/Models/item.py similarity index 100% rename from solvedac_community/Models/item.py rename to solvedac_community/Schemas/Models/item.py diff --git a/solvedac_community/Models/organization.py b/solvedac_community/Schemas/Models/organization.py similarity index 96% rename from solvedac_community/Models/organization.py rename to solvedac_community/Schemas/Models/organization.py index 321438c..84c4a16 100644 --- a/solvedac_community/Models/organization.py +++ b/solvedac_community/Schemas/Models/organization.py @@ -14,7 +14,7 @@ """ from dataclasses import dataclass -from typing import Dict, Union, List +from typing import Dict, Union @dataclass diff --git a/solvedac_community/Models/problem.py b/solvedac_community/Schemas/Models/problem.py similarity index 94% rename from solvedac_community/Models/problem.py rename to solvedac_community/Schemas/Models/problem.py index ecffdd1..26e99b4 100644 --- a/solvedac_community/Models/problem.py +++ b/solvedac_community/Schemas/Models/problem.py @@ -16,7 +16,7 @@ from dataclasses import dataclass from typing import Dict, Union -from .problem_level import ProblemLevel +from solvedac_community.Schemas.Enums.problem_level import ProblemLevel @dataclass diff --git a/solvedac_community/Models/problem_level_data.py b/solvedac_community/Schemas/Models/problem_level_data.py similarity index 91% rename from solvedac_community/Models/problem_level_data.py rename to solvedac_community/Schemas/Models/problem_level_data.py index 29e386c..13066b4 100644 --- a/solvedac_community/Models/problem_level_data.py +++ b/solvedac_community/Schemas/Models/problem_level_data.py @@ -15,7 +15,8 @@ from dataclasses import dataclass from typing import Dict -from .problem_level import ProblemLevel + +from solvedac_community.Schemas.Enums.problem_level import ProblemLevel @dataclass diff --git a/solvedac_community/Models/problem_search_data.py b/solvedac_community/Schemas/Models/problem_search_data.py similarity index 100% rename from solvedac_community/Models/problem_search_data.py rename to solvedac_community/Schemas/Models/problem_search_data.py diff --git a/solvedac_community/Models/problem_stats.py b/solvedac_community/Schemas/Models/problem_stats.py similarity index 90% rename from solvedac_community/Models/problem_stats.py rename to solvedac_community/Schemas/Models/problem_stats.py index bace4c2..eff7868 100644 --- a/solvedac_community/Models/problem_stats.py +++ b/solvedac_community/Schemas/Models/problem_stats.py @@ -14,9 +14,9 @@ """ from dataclasses import dataclass -from typing import Dict, Union +from typing import Dict -from .problem_level import ProblemLevel +from solvedac_community.Schemas.Enums.problem_level import ProblemLevel @dataclass diff --git a/solvedac_community/Models/problem_tag.py b/solvedac_community/Schemas/Models/problem_tag.py similarity index 100% rename from solvedac_community/Models/problem_tag.py rename to solvedac_community/Schemas/Models/problem_tag.py diff --git a/solvedac_community/Models/settings.py b/solvedac_community/Schemas/Models/settings.py similarity index 98% rename from solvedac_community/Models/settings.py rename to solvedac_community/Schemas/Models/settings.py index 91470cb..f0f32c4 100644 --- a/solvedac_community/Models/settings.py +++ b/solvedac_community/Schemas/Models/settings.py @@ -14,7 +14,6 @@ """ from dataclasses import dataclass -from typing import Dict, Union @dataclass @@ -41,4 +40,3 @@ def __init__(self, data: dict[str, str]): self.twitter_post_on_problem_solve = data.get("twitter_post_on_problem_solve", "false") == "true" self.twitter_post_on_rating_increase = data.get("twitter_post_on_rating_increase", "false") == "true" self.twitter_post_on_tier_increase = data.get("twitter_post_on_tier_increase", "false") == "true" - diff --git a/solvedac_community/Schemas/Models/simplified_problem.py b/solvedac_community/Schemas/Models/simplified_problem.py new file mode 100644 index 0000000..dbd90c5 --- /dev/null +++ b/solvedac_community/Schemas/Models/simplified_problem.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from dataclasses import dataclass +from typing import Dict, Union + + +@dataclass +class SimplifiedProblem: + id: int + title: str + level: int + solved: int + caption: str + description: str + href: str + + def __init__(self, data: Dict[str, Union[int, str]]): + self.id: int = data["id"] + self.title: str = data["title"] + self.level: int = data["level"] + self.solved: int = data["solved"] + self.caption: str = data["caption"] + self.description: str = data["description"] + self.href: str = data["href"] diff --git a/solvedac_community/Schemas/Models/simplified_tag.py b/solvedac_community/Schemas/Models/simplified_tag.py new file mode 100644 index 0000000..ef34af4 --- /dev/null +++ b/solvedac_community/Schemas/Models/simplified_tag.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from dataclasses import dataclass +from typing import Dict, Union + + +@dataclass +class SimplifiedTag: + key: str + name: str + problem_count: int + caption: str + description: str + href: str + + def __init__(self, data: Dict[str, Union[str, int]]): + self.key: str = data["key"] + self.name: str = data["name"] + self.problem_count: int = data["problemCount"] + self.caption: str = data["caption"] + self.description: str = data["description"] + self.href: str = data["href"] diff --git a/solvedac_community/Models/auto_completion_data.py b/solvedac_community/Schemas/Models/simplified_user.py similarity index 54% rename from solvedac_community/Models/auto_completion_data.py rename to solvedac_community/Schemas/Models/simplified_user.py index f27b377..997249e 100644 --- a/solvedac_community/Models/auto_completion_data.py +++ b/solvedac_community/Schemas/Models/simplified_user.py @@ -15,59 +15,11 @@ import datetime from dataclasses import dataclass -from typing import Dict, Union, List +from typing import Dict, Union -from .class_decoration import ClassDecoration -from .user_tier import UserTier -from ..utils import get_datetime_from_string - - -@dataclass() -class AutoCompleteText: - caption: str - description: str - - def __init__(self, data: Dict[str, str]): - self.caption: str = data["caption"] - self.description: str = data["description"] - - -@dataclass -class SimplifiedProblem: - id: int - title: str - level: int - solved: int - caption: str - description: str - href: str - - def __init__(self, data: Dict[str, Union[int, str]]): - self.id: int = data["id"] - self.title: str = data["title"] - self.level: int = data["level"] - self.solved: int = data["solved"] - self.caption: str = data["caption"] - self.description: str = data["description"] - self.href: str = data["href"] - - -@dataclass -class SimplifiedTag: - key: str - name: str - problem_count: int - caption: str - description: str - href: str - - def __init__(self, data: Dict[str, Union[str, int]]): - self.key: str = data["key"] - self.name: str = data["name"] - self.problem_count: int = data["problemCount"] - self.caption: str = data["caption"] - self.description: str = data["description"] - self.href: str = data["href"] +from solvedac_community.Schemas.Enums.class_decoration import ClassDecoration +from solvedac_community.Schemas.Enums.user_tier import UserTier +from solvedac_community.utils import get_datetime_from_string @dataclass @@ -119,23 +71,3 @@ def __init__(self, data: Dict[str, Union[str, int, bool, None]]): self.joined_at: datetime.datetime = get_datetime_from_string(data["joinedAt"]) self.banned_until: datetime.datetime = get_datetime_from_string(data["bannedUntil"]) self.pro_until: datetime.datetime = get_datetime_from_string(data["proUntil"]) - - -@dataclass -class AutoCompletionData: - autocomplete: List[AutoCompleteText] - problems: List[SimplifiedProblem] - problem_count: int - tags: List[SimplifiedTag] - tag_count: int - users: List[SimplifiedUser] - user_count: int - - def __init__(self, data: Dict[str, Union[list, int]]): - self.autocomplete: List[AutoCompleteText] = [AutoCompleteText(dat) for dat in data["autocomplete"]] - self.problems: List[SimplifiedProblem] = [SimplifiedProblem(dat) for dat in data["problems"]] - self.problem_count: int = data["problemCount"] - self.tags: List[SimplifiedTag] = [SimplifiedTag(dat) for dat in data["tags"]] - self.tag_count: int = data["tagCount"] - self.users: List[SimplifiedUser] = [SimplifiedUser(dat) for dat in data["users"]] - self.user_count: int = data["userCount"] diff --git a/solvedac_community/Models/solvedac_statistics.py b/solvedac_community/Schemas/Models/solvedac_statistics.py similarity index 100% rename from solvedac_community/Models/solvedac_statistics.py rename to solvedac_community/Schemas/Models/solvedac_statistics.py diff --git a/solvedac_community/Models/tag_display_name.py b/solvedac_community/Schemas/Models/tag_display_name.py similarity index 100% rename from solvedac_community/Models/tag_display_name.py rename to solvedac_community/Schemas/Models/tag_display_name.py diff --git a/solvedac_community/Models/tagged_problem.py b/solvedac_community/Schemas/Models/tagged_problem.py similarity index 95% rename from solvedac_community/Models/tagged_problem.py rename to solvedac_community/Schemas/Models/tagged_problem.py index 4e43af5..3d45015 100644 --- a/solvedac_community/Models/tagged_problem.py +++ b/solvedac_community/Schemas/Models/tagged_problem.py @@ -16,8 +16,8 @@ from dataclasses import dataclass from typing import Dict, Union, List +from solvedac_community.Schemas.Enums.problem_level import ProblemLevel from .problem_tag import ProblemTag -from .problem_level import ProblemLevel @dataclass diff --git a/solvedac_community/Models/user.py b/solvedac_community/Schemas/Models/user.py similarity index 91% rename from solvedac_community/Models/user.py rename to solvedac_community/Schemas/Models/user.py index 4720bb1..eab4a85 100644 --- a/solvedac_community/Models/user.py +++ b/solvedac_community/Schemas/Models/user.py @@ -13,13 +13,13 @@ OTHER DEALINGS IN THE SOFTWARE. """ -from dataclasses import dataclass -from typing import Dict, Any, Union import datetime +from dataclasses import dataclass +from typing import Dict, Union -from .user_tier import UserTier -from .class_decoration import ClassDecoration -from ..utils import get_datetime_from_string +from solvedac_community.Schemas.Enums.class_decoration import ClassDecoration +from solvedac_community.Schemas.Enums.user_tier import UserTier +from solvedac_community.utils import get_datetime_from_string @dataclass diff --git a/solvedac_community/Schemas/__init__.py b/solvedac_community/Schemas/__init__.py new file mode 100644 index 0000000..5169b18 --- /dev/null +++ b/solvedac_community/Schemas/__init__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2023 DevRuby +MIT License +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +from . import Enums +from . import Models diff --git a/solvedac_community/client.py b/solvedac_community/client.py index 560586e..23c1045 100644 --- a/solvedac_community/client.py +++ b/solvedac_community/client.py @@ -17,8 +17,8 @@ import json from typing import Optional, List, Iterable, Union -from .HTTPClients import * -from .Models import * +from solvedac_community.HTTPClients import * +from solvedac_community.Schemas import * class Client: @@ -34,31 +34,31 @@ def __init__(self, solvedac_token: Optional[str] = None, http_library: HTTPClien self.http_client = get_http_client(self.loop, solvedac_token=solvedac_token, lib=http_library) self.has_token = bool(solvedac_token) - async def get_user(self, handle: str) -> User: + async def get_user(self, handle: str) -> Models.User: response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/user/show", params={"handle": handle}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return User(json_data) + return Models.User(json_data) - async def get_user_organizations(self, handle: str) -> List[Organization]: + async def get_user_organizations(self, handle: str) -> List[Models.Organization]: response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/user/organizations", params={"handle": handle}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return [Organization(dat) for dat in json_data] + return [Models.Organization(dat) for dat in json_data] - async def get_user_problem_stats(self, handle: str) -> List[ProblemStats]: + async def get_user_problem_stats(self, handle: str) -> List[Models.ProblemStats]: response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/user/problem_stats", params={"handle": handle}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return [ProblemStats(dat) for dat in json_data] + return [Models.ProblemStats(dat) for dat in json_data] - async def get_background(self, background_id: str) -> Background: + async def get_background(self, background_id: str) -> Models.Background: response: ResponseData = await self.http_client.request( Route( RequestMethod.GET, @@ -68,15 +68,15 @@ async def get_background(self, background_id: str) -> Background: ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return Background(json_data) + return Models.Background(json_data) - async def get_badge(self, badge_id: str) -> Badge: + async def get_badge(self, badge_id: str) -> Models.Badge: response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/badge/show", params={"badgeId": badge_id}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return Badge(json_data) + return Models.Badge(json_data) async def get_coins_exchange_rate(self) -> int: response: ResponseData = await self.http_client.request(Route(RequestMethod.GET, f"/coins/exchange_rate")) @@ -84,48 +84,48 @@ async def get_coins_exchange_rate(self) -> int: json_data: dict = json.loads(response.response_data) return json_data["rate"] - async def get_coinshop_products(self) -> List[CoinshopProduct]: + async def get_coinshop_products(self) -> List[Models.CoinshopProduct]: response: ResponseData = await self.http_client.request(Route(RequestMethod.GET, f"/coins/shop/list")) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return [CoinshopProduct(d) for d in json_data] + return [Models.CoinshopProduct(d) for d in json_data] - async def get_site_stats(self) -> SolvedAcStatistics: + async def get_site_stats(self) -> Models.SolvedAcStatistics: response: ResponseData = await self.http_client.request(Route(RequestMethod.GET, f"/site/stats")) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return SolvedAcStatistics(json_data) + return Models.SolvedAcStatistics(json_data) - async def get_problem_by_id(self, problem_id: int) -> TaggedProblem: + async def get_problem_by_id(self, problem_id: int) -> Models.TaggedProblem: response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/problem/show", params={"problemId": problem_id}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return TaggedProblem(json_data) + return Models.TaggedProblem(json_data) - async def get_problem_by_id_array(self, problem_ids: Iterable[Union[int, str]]) -> List[TaggedProblem]: + async def get_problem_by_id_array(self, problem_ids: Iterable[Union[int, str]]) -> List[Models.TaggedProblem]: query = ",".join(map(str, problem_ids)) response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/problem/lookup", params={"problemIds": query}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return [TaggedProblem(d) for d in json_data] + return [Models.TaggedProblem(d) for d in json_data] - async def get_problem_level(self) -> List[ProblemLevelData]: + async def get_problem_level(self) -> List[Models.ProblemLevelData]: response: ResponseData = await self.http_client.request(Route(RequestMethod.GET, f"/problem/level")) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return [ProblemLevelData(d) for d in json_data] + return [Models.ProblemLevelData(d) for d in json_data] async def search_problem( self, query: str, - direction: Union[SortDirection, str], + direction: Union[Enums.SortDirection, str], page: int, - sort: Union[SortType, str], - ) -> ProblemSearchData: + sort: Union[Enums.SortType, str], + ) -> Models.ProblemSearchData: response: ResponseData = await self.http_client.request( Route( RequestMethod.GET, @@ -135,19 +135,19 @@ async def search_problem( ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return ProblemSearchData(json_data) + return Models.ProblemSearchData(json_data) - async def get_search_auto_completion(self, query: str) -> AutoCompletionData: + async def get_search_auto_completion(self, query: str) -> Models.AutoCompletionData: response: ResponseData = await self.http_client.request( Route(RequestMethod.GET, f"/search/suggestion", params={"query": query}) ) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return AutoCompletionData(json_data) + return Models.AutoCompletionData(json_data) - async def verify_account_credentials(self) -> AccountInfo: + async def verify_account_credentials(self) -> Models.AccountInfo: response: ResponseData = await self.http_client.request(Route(RequestMethod.GET, "/account/verify_credentials")) assert response.status == 200, "HTTP Response Status Code is not 200\nStatus Code : %d" % response.status json_data: dict = json.loads(response.response_data) - return AccountInfo(json_data) + return Models.AccountInfo(json_data)