From 738c3076707a2a029cb296e248eb03dcf5c141f5 Mon Sep 17 00:00:00 2001 From: DevRuby <60344644+dev-ruby@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:41:59 +0900 Subject: [PATCH 1/6] style: Sort imports --- solvedac_community/Models/__init__.py | 2 +- solvedac_community/Models/account_info.py | 6 +++--- solvedac_community/Models/background.py | 2 +- solvedac_community/Models/badge.py | 2 +- solvedac_community/Models/coinshop_product.py | 2 +- solvedac_community/Models/organization.py | 2 +- solvedac_community/Models/problem_level_data.py | 1 + solvedac_community/Models/problem_stats.py | 2 +- solvedac_community/Models/settings.py | 1 - solvedac_community/Models/tagged_problem.py | 2 +- solvedac_community/Models/user.py | 6 +++--- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/solvedac_community/Models/__init__.py b/solvedac_community/Models/__init__.py index 991fa76..a6359f5 100644 --- a/solvedac_community/Models/__init__.py +++ b/solvedac_community/Models/__init__.py @@ -13,6 +13,7 @@ OTHER DEALINGS IN THE SOFTWARE. """ +from .account_info import AccountInfo from .author import Author from .auto_completion_data import AutoCompletionData from .background import Background @@ -28,4 +29,3 @@ 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/Models/account_info.py index 0d04729..d4be40e 100644 --- a/solvedac_community/Models/account_info.py +++ b/solvedac_community/Models/account_info.py @@ -13,14 +13,14 @@ OTHER DEALINGS IN THE SOFTWARE. """ -from datetime import datetime from dataclasses import dataclass +from datetime import datetime +from typing import Dict, Union, List + from .auto_completion_data import SimplifiedUser from .settings import Settings from ..utils import get_datetime_from_string -from typing import Dict, Union, List - @dataclass class EmoticonInfo: diff --git a/solvedac_community/Models/background.py b/solvedac_community/Models/background.py index 50396e0..5734072 100644 --- a/solvedac_community/Models/background.py +++ b/solvedac_community/Models/background.py @@ -14,7 +14,7 @@ """ from dataclasses import dataclass -from typing import Dict, Union, Optional, List +from typing import Dict, Union, List from .author import Author diff --git a/solvedac_community/Models/badge.py b/solvedac_community/Models/badge.py index 0f6d813..96057df 100644 --- a/solvedac_community/Models/badge.py +++ b/solvedac_community/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 .badge_tier import BadgeTier @dataclass diff --git a/solvedac_community/Models/coinshop_product.py b/solvedac_community/Models/coinshop_product.py index f5c4af7..cac5f2c 100644 --- a/solvedac_community/Models/coinshop_product.py +++ b/solvedac_community/Models/coinshop_product.py @@ -14,7 +14,7 @@ """ from dataclasses import dataclass -from typing import Dict, Optional, Union +from typing import Dict, Union from .item import Item from .price_unit import PriceUnit diff --git a/solvedac_community/Models/organization.py b/solvedac_community/Models/organization.py index 321438c..84c4a16 100644 --- a/solvedac_community/Models/organization.py +++ b/solvedac_community/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_level_data.py b/solvedac_community/Models/problem_level_data.py index 29e386c..e6728d3 100644 --- a/solvedac_community/Models/problem_level_data.py +++ b/solvedac_community/Models/problem_level_data.py @@ -15,6 +15,7 @@ from dataclasses import dataclass from typing import Dict + from .problem_level import ProblemLevel diff --git a/solvedac_community/Models/problem_stats.py b/solvedac_community/Models/problem_stats.py index bace4c2..b1622d8 100644 --- a/solvedac_community/Models/problem_stats.py +++ b/solvedac_community/Models/problem_stats.py @@ -14,7 +14,7 @@ """ from dataclasses import dataclass -from typing import Dict, Union +from typing import Dict from .problem_level import ProblemLevel diff --git a/solvedac_community/Models/settings.py b/solvedac_community/Models/settings.py index 91470cb..7449dc4 100644 --- a/solvedac_community/Models/settings.py +++ b/solvedac_community/Models/settings.py @@ -14,7 +14,6 @@ """ from dataclasses import dataclass -from typing import Dict, Union @dataclass diff --git a/solvedac_community/Models/tagged_problem.py b/solvedac_community/Models/tagged_problem.py index 4e43af5..15484d7 100644 --- a/solvedac_community/Models/tagged_problem.py +++ b/solvedac_community/Models/tagged_problem.py @@ -16,8 +16,8 @@ from dataclasses import dataclass from typing import Dict, Union, List -from .problem_tag import ProblemTag from .problem_level import ProblemLevel +from .problem_tag import ProblemTag @dataclass diff --git a/solvedac_community/Models/user.py b/solvedac_community/Models/user.py index 4720bb1..114e9d3 100644 --- a/solvedac_community/Models/user.py +++ b/solvedac_community/Models/user.py @@ -13,12 +13,12 @@ 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 .user_tier import UserTier from ..utils import get_datetime_from_string From 8e6277471c4e4f345652ba5044b65dd0b3d631b5 Mon Sep 17 00:00:00 2001 From: DevRuby <60344644+dev-ruby@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:52:03 +0900 Subject: [PATCH 2/6] refactor: Change `Models` directory name to `Schemas` --- solvedac_community/{Models => Schemas}/__init__.py | 0 solvedac_community/{Models => Schemas}/account_info.py | 0 solvedac_community/{Models => Schemas}/author.py | 0 solvedac_community/{Models => Schemas}/auto_completion_data.py | 0 solvedac_community/{Models => Schemas}/background.py | 0 solvedac_community/{Models => Schemas}/badge.py | 0 solvedac_community/{Models => Schemas}/badge_category.py | 0 solvedac_community/{Models => Schemas}/badge_tier.py | 0 solvedac_community/{Models => Schemas}/class_decoration.py | 0 solvedac_community/{Models => Schemas}/coinshop_product.py | 0 solvedac_community/{Models => Schemas}/item.py | 0 solvedac_community/{Models => Schemas}/organization.py | 0 solvedac_community/{Models => Schemas}/price_unit.py | 0 solvedac_community/{Models => Schemas}/problem.py | 0 solvedac_community/{Models => Schemas}/problem_level.py | 0 solvedac_community/{Models => Schemas}/problem_level_data.py | 0 solvedac_community/{Models => Schemas}/problem_search_data.py | 0 solvedac_community/{Models => Schemas}/problem_stats.py | 0 solvedac_community/{Models => Schemas}/problem_tag.py | 0 solvedac_community/{Models => Schemas}/settings.py | 0 solvedac_community/{Models => Schemas}/solvedac_statistics.py | 0 solvedac_community/{Models => Schemas}/sort_direction.py | 0 solvedac_community/{Models => Schemas}/sort_type.py | 0 solvedac_community/{Models => Schemas}/tag_display_name.py | 0 solvedac_community/{Models => Schemas}/tagged_problem.py | 0 solvedac_community/{Models => Schemas}/user.py | 0 solvedac_community/{Models => Schemas}/user_tier.py | 0 solvedac_community/client.py | 2 +- 28 files changed, 1 insertion(+), 1 deletion(-) rename solvedac_community/{Models => Schemas}/__init__.py (100%) rename solvedac_community/{Models => Schemas}/account_info.py (100%) rename solvedac_community/{Models => Schemas}/author.py (100%) rename solvedac_community/{Models => Schemas}/auto_completion_data.py (100%) rename solvedac_community/{Models => Schemas}/background.py (100%) rename solvedac_community/{Models => Schemas}/badge.py (100%) rename solvedac_community/{Models => Schemas}/badge_category.py (100%) rename solvedac_community/{Models => Schemas}/badge_tier.py (100%) rename solvedac_community/{Models => Schemas}/class_decoration.py (100%) rename solvedac_community/{Models => Schemas}/coinshop_product.py (100%) rename solvedac_community/{Models => Schemas}/item.py (100%) rename solvedac_community/{Models => Schemas}/organization.py (100%) rename solvedac_community/{Models => Schemas}/price_unit.py (100%) rename solvedac_community/{Models => Schemas}/problem.py (100%) rename solvedac_community/{Models => Schemas}/problem_level.py (100%) rename solvedac_community/{Models => Schemas}/problem_level_data.py (100%) rename solvedac_community/{Models => Schemas}/problem_search_data.py (100%) rename solvedac_community/{Models => Schemas}/problem_stats.py (100%) rename solvedac_community/{Models => Schemas}/problem_tag.py (100%) rename solvedac_community/{Models => Schemas}/settings.py (100%) rename solvedac_community/{Models => Schemas}/solvedac_statistics.py (100%) rename solvedac_community/{Models => Schemas}/sort_direction.py (100%) rename solvedac_community/{Models => Schemas}/sort_type.py (100%) rename solvedac_community/{Models => Schemas}/tag_display_name.py (100%) rename solvedac_community/{Models => Schemas}/tagged_problem.py (100%) rename solvedac_community/{Models => Schemas}/user.py (100%) rename solvedac_community/{Models => Schemas}/user_tier.py (100%) diff --git a/solvedac_community/Models/__init__.py b/solvedac_community/Schemas/__init__.py similarity index 100% rename from solvedac_community/Models/__init__.py rename to solvedac_community/Schemas/__init__.py diff --git a/solvedac_community/Models/account_info.py b/solvedac_community/Schemas/account_info.py similarity index 100% rename from solvedac_community/Models/account_info.py rename to solvedac_community/Schemas/account_info.py diff --git a/solvedac_community/Models/author.py b/solvedac_community/Schemas/author.py similarity index 100% rename from solvedac_community/Models/author.py rename to solvedac_community/Schemas/author.py diff --git a/solvedac_community/Models/auto_completion_data.py b/solvedac_community/Schemas/auto_completion_data.py similarity index 100% rename from solvedac_community/Models/auto_completion_data.py rename to solvedac_community/Schemas/auto_completion_data.py diff --git a/solvedac_community/Models/background.py b/solvedac_community/Schemas/background.py similarity index 100% rename from solvedac_community/Models/background.py rename to solvedac_community/Schemas/background.py diff --git a/solvedac_community/Models/badge.py b/solvedac_community/Schemas/badge.py similarity index 100% rename from solvedac_community/Models/badge.py rename to solvedac_community/Schemas/badge.py diff --git a/solvedac_community/Models/badge_category.py b/solvedac_community/Schemas/badge_category.py similarity index 100% rename from solvedac_community/Models/badge_category.py rename to solvedac_community/Schemas/badge_category.py diff --git a/solvedac_community/Models/badge_tier.py b/solvedac_community/Schemas/badge_tier.py similarity index 100% rename from solvedac_community/Models/badge_tier.py rename to solvedac_community/Schemas/badge_tier.py diff --git a/solvedac_community/Models/class_decoration.py b/solvedac_community/Schemas/class_decoration.py similarity index 100% rename from solvedac_community/Models/class_decoration.py rename to solvedac_community/Schemas/class_decoration.py diff --git a/solvedac_community/Models/coinshop_product.py b/solvedac_community/Schemas/coinshop_product.py similarity index 100% rename from solvedac_community/Models/coinshop_product.py rename to solvedac_community/Schemas/coinshop_product.py diff --git a/solvedac_community/Models/item.py b/solvedac_community/Schemas/item.py similarity index 100% rename from solvedac_community/Models/item.py rename to solvedac_community/Schemas/item.py diff --git a/solvedac_community/Models/organization.py b/solvedac_community/Schemas/organization.py similarity index 100% rename from solvedac_community/Models/organization.py rename to solvedac_community/Schemas/organization.py diff --git a/solvedac_community/Models/price_unit.py b/solvedac_community/Schemas/price_unit.py similarity index 100% rename from solvedac_community/Models/price_unit.py rename to solvedac_community/Schemas/price_unit.py diff --git a/solvedac_community/Models/problem.py b/solvedac_community/Schemas/problem.py similarity index 100% rename from solvedac_community/Models/problem.py rename to solvedac_community/Schemas/problem.py diff --git a/solvedac_community/Models/problem_level.py b/solvedac_community/Schemas/problem_level.py similarity index 100% rename from solvedac_community/Models/problem_level.py rename to solvedac_community/Schemas/problem_level.py diff --git a/solvedac_community/Models/problem_level_data.py b/solvedac_community/Schemas/problem_level_data.py similarity index 100% rename from solvedac_community/Models/problem_level_data.py rename to solvedac_community/Schemas/problem_level_data.py diff --git a/solvedac_community/Models/problem_search_data.py b/solvedac_community/Schemas/problem_search_data.py similarity index 100% rename from solvedac_community/Models/problem_search_data.py rename to solvedac_community/Schemas/problem_search_data.py diff --git a/solvedac_community/Models/problem_stats.py b/solvedac_community/Schemas/problem_stats.py similarity index 100% rename from solvedac_community/Models/problem_stats.py rename to solvedac_community/Schemas/problem_stats.py diff --git a/solvedac_community/Models/problem_tag.py b/solvedac_community/Schemas/problem_tag.py similarity index 100% rename from solvedac_community/Models/problem_tag.py rename to solvedac_community/Schemas/problem_tag.py diff --git a/solvedac_community/Models/settings.py b/solvedac_community/Schemas/settings.py similarity index 100% rename from solvedac_community/Models/settings.py rename to solvedac_community/Schemas/settings.py diff --git a/solvedac_community/Models/solvedac_statistics.py b/solvedac_community/Schemas/solvedac_statistics.py similarity index 100% rename from solvedac_community/Models/solvedac_statistics.py rename to solvedac_community/Schemas/solvedac_statistics.py diff --git a/solvedac_community/Models/sort_direction.py b/solvedac_community/Schemas/sort_direction.py similarity index 100% rename from solvedac_community/Models/sort_direction.py rename to solvedac_community/Schemas/sort_direction.py diff --git a/solvedac_community/Models/sort_type.py b/solvedac_community/Schemas/sort_type.py similarity index 100% rename from solvedac_community/Models/sort_type.py rename to solvedac_community/Schemas/sort_type.py diff --git a/solvedac_community/Models/tag_display_name.py b/solvedac_community/Schemas/tag_display_name.py similarity index 100% rename from solvedac_community/Models/tag_display_name.py rename to solvedac_community/Schemas/tag_display_name.py diff --git a/solvedac_community/Models/tagged_problem.py b/solvedac_community/Schemas/tagged_problem.py similarity index 100% rename from solvedac_community/Models/tagged_problem.py rename to solvedac_community/Schemas/tagged_problem.py diff --git a/solvedac_community/Models/user.py b/solvedac_community/Schemas/user.py similarity index 100% rename from solvedac_community/Models/user.py rename to solvedac_community/Schemas/user.py diff --git a/solvedac_community/Models/user_tier.py b/solvedac_community/Schemas/user_tier.py similarity index 100% rename from solvedac_community/Models/user_tier.py rename to solvedac_community/Schemas/user_tier.py diff --git a/solvedac_community/client.py b/solvedac_community/client.py index 560586e..43167af 100644 --- a/solvedac_community/client.py +++ b/solvedac_community/client.py @@ -18,7 +18,7 @@ from typing import Optional, List, Iterable, Union from .HTTPClients import * -from .Models import * +from .Schemas import * class Client: From 78dbb5b5d11b5e1f41d77c285d762cf7cf5994e3 Mon Sep 17 00:00:00 2001 From: DevRuby <60344644+dev-ruby@users.noreply.github.com> Date: Fri, 16 Jun 2023 17:37:05 +0900 Subject: [PATCH 3/6] refactor: Separate enums and models into different directories --- solvedac_community/Schemas/Enums/__init__.py | 23 ++++++++ .../Schemas/{ => Enums}/badge_category.py | 0 .../Schemas/{ => Enums}/badge_tier.py | 0 .../Schemas/{ => Enums}/class_decoration.py | 0 .../Schemas/{ => Enums}/price_unit.py | 0 .../Schemas/{ => Enums}/problem_level.py | 0 .../Schemas/{ => Enums}/sort_direction.py | 0 .../Schemas/{ => Enums}/sort_type.py | 0 .../Schemas/{ => Enums}/user_tier.py | 0 solvedac_community/Schemas/Models/__init__.py | 28 ++++++++++ .../Schemas/{ => Models}/account_info.py | 6 +- .../Schemas/{ => Models}/author.py | 0 .../{ => Models}/auto_completion_data.py | 6 +- .../Schemas/{ => Models}/background.py | 2 +- .../Schemas/{ => Models}/badge.py | 4 +- .../Schemas/{ => Models}/coinshop_product.py | 4 +- .../Schemas/{ => Models}/item.py | 0 .../Schemas/{ => Models}/organization.py | 0 .../Schemas/{ => Models}/problem.py | 2 +- .../{ => Models}/problem_level_data.py | 2 +- .../{ => Models}/problem_search_data.py | 0 .../Schemas/{ => Models}/problem_stats.py | 2 +- .../Schemas/{ => Models}/problem_tag.py | 0 .../Schemas/{ => Models}/settings.py | 0 .../{ => Models}/solvedac_statistics.py | 0 .../Schemas/{ => Models}/tag_display_name.py | 0 .../Schemas/{ => Models}/tagged_problem.py | 2 +- .../Schemas/{ => Models}/user.py | 6 +- solvedac_community/Schemas/__init__.py | 18 +----- solvedac_community/client.py | 56 +++++++++---------- 30 files changed, 99 insertions(+), 62 deletions(-) create mode 100644 solvedac_community/Schemas/Enums/__init__.py rename solvedac_community/Schemas/{ => Enums}/badge_category.py (100%) rename solvedac_community/Schemas/{ => Enums}/badge_tier.py (100%) rename solvedac_community/Schemas/{ => Enums}/class_decoration.py (100%) rename solvedac_community/Schemas/{ => Enums}/price_unit.py (100%) rename solvedac_community/Schemas/{ => Enums}/problem_level.py (100%) rename solvedac_community/Schemas/{ => Enums}/sort_direction.py (100%) rename solvedac_community/Schemas/{ => Enums}/sort_type.py (100%) rename solvedac_community/Schemas/{ => Enums}/user_tier.py (100%) create mode 100644 solvedac_community/Schemas/Models/__init__.py rename solvedac_community/Schemas/{ => Models}/account_info.py (89%) rename solvedac_community/Schemas/{ => Models}/author.py (100%) rename solvedac_community/Schemas/{ => Models}/auto_completion_data.py (95%) rename solvedac_community/Schemas/{ => Models}/background.py (96%) rename solvedac_community/Schemas/{ => Models}/badge.py (89%) rename solvedac_community/Schemas/{ => Models}/coinshop_product.py (91%) rename solvedac_community/Schemas/{ => Models}/item.py (100%) rename solvedac_community/Schemas/{ => Models}/organization.py (100%) rename solvedac_community/Schemas/{ => Models}/problem.py (94%) rename solvedac_community/Schemas/{ => Models}/problem_level_data.py (91%) rename solvedac_community/Schemas/{ => Models}/problem_search_data.py (100%) rename solvedac_community/Schemas/{ => Models}/problem_stats.py (92%) rename solvedac_community/Schemas/{ => Models}/problem_tag.py (100%) rename solvedac_community/Schemas/{ => Models}/settings.py (100%) rename solvedac_community/Schemas/{ => Models}/solvedac_statistics.py (100%) rename solvedac_community/Schemas/{ => Models}/tag_display_name.py (100%) rename solvedac_community/Schemas/{ => Models}/tagged_problem.py (95%) rename solvedac_community/Schemas/{ => Models}/user.py (93%) 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/Schemas/badge_category.py b/solvedac_community/Schemas/Enums/badge_category.py similarity index 100% rename from solvedac_community/Schemas/badge_category.py rename to solvedac_community/Schemas/Enums/badge_category.py diff --git a/solvedac_community/Schemas/badge_tier.py b/solvedac_community/Schemas/Enums/badge_tier.py similarity index 100% rename from solvedac_community/Schemas/badge_tier.py rename to solvedac_community/Schemas/Enums/badge_tier.py diff --git a/solvedac_community/Schemas/class_decoration.py b/solvedac_community/Schemas/Enums/class_decoration.py similarity index 100% rename from solvedac_community/Schemas/class_decoration.py rename to solvedac_community/Schemas/Enums/class_decoration.py diff --git a/solvedac_community/Schemas/price_unit.py b/solvedac_community/Schemas/Enums/price_unit.py similarity index 100% rename from solvedac_community/Schemas/price_unit.py rename to solvedac_community/Schemas/Enums/price_unit.py diff --git a/solvedac_community/Schemas/problem_level.py b/solvedac_community/Schemas/Enums/problem_level.py similarity index 100% rename from solvedac_community/Schemas/problem_level.py rename to solvedac_community/Schemas/Enums/problem_level.py diff --git a/solvedac_community/Schemas/sort_direction.py b/solvedac_community/Schemas/Enums/sort_direction.py similarity index 100% rename from solvedac_community/Schemas/sort_direction.py rename to solvedac_community/Schemas/Enums/sort_direction.py diff --git a/solvedac_community/Schemas/sort_type.py b/solvedac_community/Schemas/Enums/sort_type.py similarity index 100% rename from solvedac_community/Schemas/sort_type.py rename to solvedac_community/Schemas/Enums/sort_type.py diff --git a/solvedac_community/Schemas/user_tier.py b/solvedac_community/Schemas/Enums/user_tier.py similarity index 100% rename from solvedac_community/Schemas/user_tier.py rename to solvedac_community/Schemas/Enums/user_tier.py diff --git a/solvedac_community/Schemas/Models/__init__.py b/solvedac_community/Schemas/Models/__init__.py new file mode 100644 index 0000000..2a04280 --- /dev/null +++ b/solvedac_community/Schemas/Models/__init__.py @@ -0,0 +1,28 @@ +# -*- 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 .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_data import ProblemLevelData +from .problem_search_data import ProblemSearchData +from .problem_stats import ProblemStats +from .solvedac_statistics import SolvedAcStatistics +from .tagged_problem import TaggedProblem +from .user import User diff --git a/solvedac_community/Schemas/account_info.py b/solvedac_community/Schemas/Models/account_info.py similarity index 89% rename from solvedac_community/Schemas/account_info.py rename to solvedac_community/Schemas/Models/account_info.py index d4be40e..7efbf56 100644 --- a/solvedac_community/Schemas/account_info.py +++ b/solvedac_community/Schemas/Models/account_info.py @@ -17,9 +17,9 @@ from datetime import datetime from typing import Dict, Union, List -from .auto_completion_data import SimplifiedUser -from .settings import Settings -from ..utils import get_datetime_from_string +from solvedac_community.Schemas.Models.auto_completion_data import SimplifiedUser +from solvedac_community.Schemas.Models.settings import Settings +from solvedac_community.utils import get_datetime_from_string @dataclass diff --git a/solvedac_community/Schemas/author.py b/solvedac_community/Schemas/Models/author.py similarity index 100% rename from solvedac_community/Schemas/author.py rename to solvedac_community/Schemas/Models/author.py diff --git a/solvedac_community/Schemas/auto_completion_data.py b/solvedac_community/Schemas/Models/auto_completion_data.py similarity index 95% rename from solvedac_community/Schemas/auto_completion_data.py rename to solvedac_community/Schemas/Models/auto_completion_data.py index f27b377..c6af784 100644 --- a/solvedac_community/Schemas/auto_completion_data.py +++ b/solvedac_community/Schemas/Models/auto_completion_data.py @@ -17,9 +17,9 @@ from dataclasses import dataclass from typing import Dict, Union, List -from .class_decoration import ClassDecoration -from .user_tier import UserTier -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/background.py b/solvedac_community/Schemas/Models/background.py similarity index 96% rename from solvedac_community/Schemas/background.py rename to solvedac_community/Schemas/Models/background.py index 5734072..cadeec6 100644 --- a/solvedac_community/Schemas/background.py +++ b/solvedac_community/Schemas/Models/background.py @@ -16,7 +16,7 @@ from dataclasses import dataclass from typing import Dict, Union, List -from .author import Author +from solvedac_community.Schemas.Models.author import Author @dataclass() diff --git a/solvedac_community/Schemas/badge.py b/solvedac_community/Schemas/Models/badge.py similarity index 89% rename from solvedac_community/Schemas/badge.py rename to solvedac_community/Schemas/Models/badge.py index 96057df..4d1ac0b 100644 --- a/solvedac_community/Schemas/badge.py +++ b/solvedac_community/Schemas/Models/badge.py @@ -16,8 +16,8 @@ from dataclasses import dataclass from typing import Dict -from .badge_category import BadgeCategory -from .badge_tier import BadgeTier +from solvedac_community.Schemas.Enums.badge_category import BadgeCategory +from solvedac_community.Schemas.Enums.badge_tier import BadgeTier @dataclass diff --git a/solvedac_community/Schemas/coinshop_product.py b/solvedac_community/Schemas/Models/coinshop_product.py similarity index 91% rename from solvedac_community/Schemas/coinshop_product.py rename to solvedac_community/Schemas/Models/coinshop_product.py index cac5f2c..b35f792 100644 --- a/solvedac_community/Schemas/coinshop_product.py +++ b/solvedac_community/Schemas/Models/coinshop_product.py @@ -16,8 +16,8 @@ from dataclasses import dataclass 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/item.py b/solvedac_community/Schemas/Models/item.py similarity index 100% rename from solvedac_community/Schemas/item.py rename to solvedac_community/Schemas/Models/item.py diff --git a/solvedac_community/Schemas/organization.py b/solvedac_community/Schemas/Models/organization.py similarity index 100% rename from solvedac_community/Schemas/organization.py rename to solvedac_community/Schemas/Models/organization.py diff --git a/solvedac_community/Schemas/problem.py b/solvedac_community/Schemas/Models/problem.py similarity index 94% rename from solvedac_community/Schemas/problem.py rename to solvedac_community/Schemas/Models/problem.py index ecffdd1..26e99b4 100644 --- a/solvedac_community/Schemas/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/Schemas/problem_level_data.py b/solvedac_community/Schemas/Models/problem_level_data.py similarity index 91% rename from solvedac_community/Schemas/problem_level_data.py rename to solvedac_community/Schemas/Models/problem_level_data.py index e6728d3..13066b4 100644 --- a/solvedac_community/Schemas/problem_level_data.py +++ b/solvedac_community/Schemas/Models/problem_level_data.py @@ -16,7 +16,7 @@ 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/Schemas/problem_search_data.py b/solvedac_community/Schemas/Models/problem_search_data.py similarity index 100% rename from solvedac_community/Schemas/problem_search_data.py rename to solvedac_community/Schemas/Models/problem_search_data.py diff --git a/solvedac_community/Schemas/problem_stats.py b/solvedac_community/Schemas/Models/problem_stats.py similarity index 92% rename from solvedac_community/Schemas/problem_stats.py rename to solvedac_community/Schemas/Models/problem_stats.py index b1622d8..eff7868 100644 --- a/solvedac_community/Schemas/problem_stats.py +++ b/solvedac_community/Schemas/Models/problem_stats.py @@ -16,7 +16,7 @@ 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/Schemas/problem_tag.py b/solvedac_community/Schemas/Models/problem_tag.py similarity index 100% rename from solvedac_community/Schemas/problem_tag.py rename to solvedac_community/Schemas/Models/problem_tag.py diff --git a/solvedac_community/Schemas/settings.py b/solvedac_community/Schemas/Models/settings.py similarity index 100% rename from solvedac_community/Schemas/settings.py rename to solvedac_community/Schemas/Models/settings.py diff --git a/solvedac_community/Schemas/solvedac_statistics.py b/solvedac_community/Schemas/Models/solvedac_statistics.py similarity index 100% rename from solvedac_community/Schemas/solvedac_statistics.py rename to solvedac_community/Schemas/Models/solvedac_statistics.py diff --git a/solvedac_community/Schemas/tag_display_name.py b/solvedac_community/Schemas/Models/tag_display_name.py similarity index 100% rename from solvedac_community/Schemas/tag_display_name.py rename to solvedac_community/Schemas/Models/tag_display_name.py diff --git a/solvedac_community/Schemas/tagged_problem.py b/solvedac_community/Schemas/Models/tagged_problem.py similarity index 95% rename from solvedac_community/Schemas/tagged_problem.py rename to solvedac_community/Schemas/Models/tagged_problem.py index 15484d7..3d45015 100644 --- a/solvedac_community/Schemas/tagged_problem.py +++ b/solvedac_community/Schemas/Models/tagged_problem.py @@ -16,7 +16,7 @@ from dataclasses import dataclass from typing import Dict, Union, List -from .problem_level import ProblemLevel +from solvedac_community.Schemas.Enums.problem_level import ProblemLevel from .problem_tag import ProblemTag diff --git a/solvedac_community/Schemas/user.py b/solvedac_community/Schemas/Models/user.py similarity index 93% rename from solvedac_community/Schemas/user.py rename to solvedac_community/Schemas/Models/user.py index 114e9d3..eab4a85 100644 --- a/solvedac_community/Schemas/user.py +++ b/solvedac_community/Schemas/Models/user.py @@ -17,9 +17,9 @@ from dataclasses import dataclass from typing import Dict, Union -from .class_decoration import ClassDecoration -from .user_tier import UserTier -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 index a6359f5..5169b18 100644 --- a/solvedac_community/Schemas/__init__.py +++ b/solvedac_community/Schemas/__init__.py @@ -13,19 +13,5 @@ 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 . import Enums +from . import Models diff --git a/solvedac_community/client.py b/solvedac_community/client.py index 43167af..9fc96a9 100644 --- a/solvedac_community/client.py +++ b/solvedac_community/client.py @@ -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) From bd3b3ff094657b40ea85ff0b93bbd84b2e608024 Mon Sep 17 00:00:00 2001 From: DevRuby <60344644+dev-ruby@users.noreply.github.com> Date: Fri, 16 Jun 2023 17:48:18 +0900 Subject: [PATCH 4/6] refactor: Separate models into individual files --- .../Schemas/Models/account_info.py | 15 +-- .../Schemas/Models/auto_complete_text.py | 27 +++++ .../Schemas/Models/auto_completion_data.py | 107 +----------------- .../Schemas/Models/emoticon_info.py | 31 +++++ .../Schemas/Models/simplified_problem.py | 37 ++++++ .../Schemas/Models/simplified_tag.py | 35 ++++++ .../Schemas/Models/simplified_user.py | 73 ++++++++++++ 7 files changed, 208 insertions(+), 117 deletions(-) create mode 100644 solvedac_community/Schemas/Models/auto_complete_text.py create mode 100644 solvedac_community/Schemas/Models/emoticon_info.py create mode 100644 solvedac_community/Schemas/Models/simplified_problem.py create mode 100644 solvedac_community/Schemas/Models/simplified_tag.py create mode 100644 solvedac_community/Schemas/Models/simplified_user.py diff --git a/solvedac_community/Schemas/Models/account_info.py b/solvedac_community/Schemas/Models/account_info.py index 7efbf56..3ef7aa1 100644 --- a/solvedac_community/Schemas/Models/account_info.py +++ b/solvedac_community/Schemas/Models/account_info.py @@ -18,24 +18,11 @@ from typing import Dict, Union, List 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 -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"] - - @dataclass class AccountInfo: user: SimplifiedUser 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 index c6af784..04ffc21 100644 --- a/solvedac_community/Schemas/Models/auto_completion_data.py +++ b/solvedac_community/Schemas/Models/auto_completion_data.py @@ -13,112 +13,13 @@ OTHER DEALINGS IN THE SOFTWARE. """ -import datetime from dataclasses import dataclass from typing import Dict, Union, List -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() -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"] - - -@dataclass -class SimplifiedUser: - handle: str - bio: str - badge_id: str - background_id: str - profile_image_url: Union[str, None] - solved_count: int - vote_count: int - class_rating: int - class_decoration: ClassDecoration - rival_count: int - tier: UserTier - rating: int - rating_by_problems_sum: int - rating_by_class: int - rating_by_solved_count: int - rating_by_vote_count: int - max_streak: int - coins: int - stardusts: int - joined_at: datetime.datetime - banned_until: datetime.datetime - pro_until: datetime.datetime - - def __init__(self, data: Dict[str, Union[str, int, bool, None]]): - self.handle: str = data["handle"] - self.bio: str = data["bio"] - self.badge_id: Union[str, None] = data.get("badge_id") - self.background_id: str = data["backgroundId"] - self.profile_image_url: Union[str, None] = data.get("profileImageUrl") - self.solved_count: int = data["solvedCount"] - self.vote_count: int = data["voteCount"] - self.class_rating: int = data["class"] - self.class_decoration: ClassDecoration = ClassDecoration(data["classDecoration"]) - self.rival_count: int = data["rivalCount"] - self.reverse_rival_count: int = data["reverseRivalCount"] - self.tier: UserTier = UserTier(data["tier"]) - self.rating: int = data["rating"] - self.rating_by_problems_sum: int = data["ratingByProblemsSum"] - self.rating_by_class: int = data["ratingByClass"] - self.rating_by_solved_count: int = data["ratingBySolvedCount"] - self.rating_by_vote_count: int = data["ratingByVoteCount"] - self.max_streak: int = data["maxStreak"] - self.coins: int = data["coins"] - self.stardusts: int = data["stardusts"] - 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"]) +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 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/Schemas/Models/simplified_problem.py b/solvedac_community/Schemas/Models/simplified_problem.py new file mode 100644 index 0000000..a73d1a6 --- /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"] \ No newline at end of file diff --git a/solvedac_community/Schemas/Models/simplified_tag.py b/solvedac_community/Schemas/Models/simplified_tag.py new file mode 100644 index 0000000..64400cb --- /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"] \ No newline at end of file diff --git a/solvedac_community/Schemas/Models/simplified_user.py b/solvedac_community/Schemas/Models/simplified_user.py new file mode 100644 index 0000000..3d4a6c8 --- /dev/null +++ b/solvedac_community/Schemas/Models/simplified_user.py @@ -0,0 +1,73 @@ +# -*- 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. +""" + +import datetime +from dataclasses import dataclass +from typing import Dict, Union + +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 +class SimplifiedUser: + handle: str + bio: str + badge_id: str + background_id: str + profile_image_url: Union[str, None] + solved_count: int + vote_count: int + class_rating: int + class_decoration: ClassDecoration + rival_count: int + tier: UserTier + rating: int + rating_by_problems_sum: int + rating_by_class: int + rating_by_solved_count: int + rating_by_vote_count: int + max_streak: int + coins: int + stardusts: int + joined_at: datetime.datetime + banned_until: datetime.datetime + pro_until: datetime.datetime + + def __init__(self, data: Dict[str, Union[str, int, bool, None]]): + self.handle: str = data["handle"] + self.bio: str = data["bio"] + self.badge_id: Union[str, None] = data.get("badge_id") + self.background_id: str = data["backgroundId"] + self.profile_image_url: Union[str, None] = data.get("profileImageUrl") + self.solved_count: int = data["solvedCount"] + self.vote_count: int = data["voteCount"] + self.class_rating: int = data["class"] + self.class_decoration: ClassDecoration = ClassDecoration(data["classDecoration"]) + self.rival_count: int = data["rivalCount"] + self.reverse_rival_count: int = data["reverseRivalCount"] + self.tier: UserTier = UserTier(data["tier"]) + self.rating: int = data["rating"] + self.rating_by_problems_sum: int = data["ratingByProblemsSum"] + self.rating_by_class: int = data["ratingByClass"] + self.rating_by_solved_count: int = data["ratingBySolvedCount"] + self.rating_by_vote_count: int = data["ratingByVoteCount"] + self.max_streak: int = data["maxStreak"] + self.coins: int = data["coins"] + self.stardusts: int = data["stardusts"] + 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"]) \ No newline at end of file From 2a531fac12536cb5baa1f9984145819ee3bc5a97 Mon Sep 17 00:00:00 2001 From: DevRuby <60344644+dev-ruby@users.noreply.github.com> Date: Fri, 16 Jun 2023 17:52:54 +0900 Subject: [PATCH 5/6] refactor: Standardize import format --- solvedac_community/HTTPClients/abstract_http_client.py | 2 +- solvedac_community/HTTPClients/aiohttp_client.py | 4 ++-- solvedac_community/HTTPClients/httpclient.py | 8 ++++---- solvedac_community/HTTPClients/httpx_client.py | 4 ++-- solvedac_community/client.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) 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/client.py b/solvedac_community/client.py index 9fc96a9..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 .Schemas import * +from solvedac_community.HTTPClients import * +from solvedac_community.Schemas import * class Client: From 0f308c328e67562452abae911f19126de07eb1b0 Mon Sep 17 00:00:00 2001 From: DevRuby <60344644+dev-ruby@users.noreply.github.com> Date: Fri, 16 Jun 2023 17:54:15 +0900 Subject: [PATCH 6/6] style: Reformat codes --- solvedac_community/Schemas/Models/settings.py | 1 - solvedac_community/Schemas/Models/simplified_problem.py | 2 +- solvedac_community/Schemas/Models/simplified_tag.py | 2 +- solvedac_community/Schemas/Models/simplified_user.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/solvedac_community/Schemas/Models/settings.py b/solvedac_community/Schemas/Models/settings.py index 7449dc4..f0f32c4 100644 --- a/solvedac_community/Schemas/Models/settings.py +++ b/solvedac_community/Schemas/Models/settings.py @@ -40,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 index a73d1a6..dbd90c5 100644 --- a/solvedac_community/Schemas/Models/simplified_problem.py +++ b/solvedac_community/Schemas/Models/simplified_problem.py @@ -34,4 +34,4 @@ def __init__(self, data: Dict[str, Union[int, str]]): self.solved: int = data["solved"] self.caption: str = data["caption"] self.description: str = data["description"] - self.href: str = data["href"] \ No newline at end of file + self.href: str = data["href"] diff --git a/solvedac_community/Schemas/Models/simplified_tag.py b/solvedac_community/Schemas/Models/simplified_tag.py index 64400cb..ef34af4 100644 --- a/solvedac_community/Schemas/Models/simplified_tag.py +++ b/solvedac_community/Schemas/Models/simplified_tag.py @@ -32,4 +32,4 @@ def __init__(self, data: Dict[str, Union[str, int]]): self.problem_count: int = data["problemCount"] self.caption: str = data["caption"] self.description: str = data["description"] - self.href: str = data["href"] \ No newline at end of file + self.href: str = data["href"] diff --git a/solvedac_community/Schemas/Models/simplified_user.py b/solvedac_community/Schemas/Models/simplified_user.py index 3d4a6c8..997249e 100644 --- a/solvedac_community/Schemas/Models/simplified_user.py +++ b/solvedac_community/Schemas/Models/simplified_user.py @@ -70,4 +70,4 @@ def __init__(self, data: Dict[str, Union[str, int, bool, None]]): self.stardusts: int = data["stardusts"] 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"]) \ No newline at end of file + self.pro_until: datetime.datetime = get_datetime_from_string(data["proUntil"])