feat: add profiel required exception; add spans to post

This commit is contained in:
firedotguy
2026-02-13 22:38:28 +03:00
parent b3b109613b
commit 6edc40308a
3 changed files with 22 additions and 8 deletions

View File

@@ -129,4 +129,8 @@ class NotMultipleChoice(Exception):
class EmptyOptions(Exception): class EmptyOptions(Exception):
def __str__(self) -> str: def __str__(self) -> str:
return 'Options cannot be empty (pre-validation)' return 'Options cannot be empty (pre-validation)'
class ProfileRequired(Exception):
def __str__(self) -> str:
return 'No profile. Please create your profile first'

View File

@@ -54,22 +54,30 @@ class Poll(_Poll):
return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f') return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f')
class _PostShort(TextObject): class Span(BaseModel):
length: int
offset: int
type: SpanType
class _PostCounts(TextObject):
likes_count: int = Field(0, alias='likesCount') likes_count: int = Field(0, alias='likesCount')
comments_count: int = Field(0, alias='commentsCount') comments_count: int = Field(0, alias='commentsCount')
reposts_count: int = Field(0, alias='repostsCount') reposts_count: int = Field(0, alias='repostsCount')
views_count: int = Field(0, alias='viewsCount') views_count: int = Field(0, alias='viewsCount')
spans: list[Span] = []
class PostShort(_PostShort):
class _PostAuthor(_PostCounts):
author: UserPost author: UserPost
class OriginalPost(PostShort): class OriginalPost(_PostAuthor):
is_deleted: bool = Field(False, alias='isDeleted') is_deleted: bool = Field(False, alias='isDeleted')
class _Post(_PostShort): class _Post(_PostCounts):
is_liked: bool = Field(False, alias='isLiked') is_liked: bool = Field(False, alias='isLiked')
is_reposted: bool = Field(False, alias='isReposted') is_reposted: bool = Field(False, alias='isReposted')
is_viewed: bool = Field(False, alias='isViewed') is_viewed: bool = Field(False, alias='isViewed')
@@ -79,13 +87,13 @@ class _Post(_PostShort):
attachments: list[PostAttach] = [] attachments: list[PostAttach] = []
comments: list[Comment] = [] comments: list[Comment] = []
original_post: OriginalPost | None = None original_post: OriginalPost | None = None # for reposts
wall_recipient_id: UUID | None = Field(None, alias='wallRecipientId') wall_recipient_id: UUID | None = Field(None, alias='wallRecipientId')
wall_recipient: UserPost | None = Field(None, alias='wallRecipient') wall_recipient: UserPost | None = Field(None, alias='wallRecipient')
class Post(_Post, PostShort): class Post(_Post, _PostAuthor):
poll: Poll | None = None poll: Poll | None = None

View File

@@ -3,7 +3,7 @@ from _io import BufferedReader
from requests import Session from requests import Session
from requests.exceptions import JSONDecodeError from requests.exceptions import JSONDecodeError
from itd.exceptions import InvalidToken, InvalidCookie, RateLimitExceeded, Unauthorized, AccountBanned from itd.exceptions import InvalidToken, InvalidCookie, RateLimitExceeded, Unauthorized, AccountBanned, ProfileRequired
s = Session() s = Session()
@@ -41,6 +41,8 @@ def fetch(token: str, method: str, url: str, params: dict = {}, files: dict[str,
raise Unauthorized() raise Unauthorized()
if res.json().get('error', {}).get('code') == 'ACCOUNT_BANNED': if res.json().get('error', {}).get('code') == 'ACCOUNT_BANNED':
raise AccountBanned() raise AccountBanned()
if res.json().get('error', {}).get('code') == 'PROFILE_REQUIRED':
raise ProfileRequired()
except (JSONDecodeError, AttributeError): except (JSONDecodeError, AttributeError):
pass # todo pass # todo