Skip to content

Commit

Permalink
Merge pull request #1696 from jarrodnorwell/bug-1693-pydantic-input-type
Browse files Browse the repository at this point in the history
Fixes Pydantic input type error for Account
  • Loading branch information
subzeroid authored Dec 16, 2023
2 parents 5280097 + 654c3ee commit 3f6c91e
Showing 1 changed file with 40 additions and 46 deletions.
86 changes: 40 additions & 46 deletions instagrapi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@
)


class TypesBaseModel(BaseModel):
model_config = ConfigDict(
coerce_numbers_to_str=True
) # (jarrodnorwell) fixed city_id issue


def validate_external_url(cls, v):
if v is None or (v.startswith("http") and "://" in v) or isinstance(v, str):
return v
raise ValidationError("external_url must been URL or string")


class Resource(BaseModel):
model_config = ConfigDict(
coerce_numbers_to_str=True
) # (jarrodnorwell) fixed pk issue

class Resource(TypesBaseModel):
pk: str
video_url: Optional[HttpUrl] = None # for Video and IGTV
thumbnail_url: HttpUrl
media_type: int


class User(BaseModel):
model_config = ConfigDict(
coerce_numbers_to_str=True
) # (jarrodnorwell) fixed city_id issue

class User(TypesBaseModel):
pk: str
username: str
full_name: str
Expand Down Expand Up @@ -69,7 +67,7 @@ class User(BaseModel):
_external_url = validator("external_url", allow_reuse=True)(validate_external_url)


class Account(BaseModel):
class Account(TypesBaseModel):
pk: str
username: str
full_name: str
Expand All @@ -87,11 +85,7 @@ class Account(BaseModel):
_external_url = validator("external_url", allow_reuse=True)(validate_external_url)


class UserShort(BaseModel):
model_config = ConfigDict(
coerce_numbers_to_str=True
) # (jarrodnorwell) fixed pk issue

class UserShort(TypesBaseModel):
pk: str
username: Optional[str] = None
full_name: Optional[str] = ""
Expand All @@ -102,13 +96,13 @@ class UserShort(BaseModel):
stories: List = []


class Usertag(BaseModel):
class Usertag(TypesBaseModel):
user: UserShort
x: float
y: float


class Location(BaseModel):
class Location(TypesBaseModel):
pk: Optional[int] = None
name: str
phone: Optional[str] = ""
Expand All @@ -127,7 +121,7 @@ class Location(BaseModel):
# directory: Optional[dict] = {}


class Media(BaseModel):
class Media(TypesBaseModel):
pk: str | int
id: str
code: str
Expand Down Expand Up @@ -156,7 +150,7 @@ class Media(BaseModel):
clips_metadata: dict = {}


class MediaXma(BaseModel):
class MediaXma(TypesBaseModel):
# media_type: int
video_url: HttpUrl # for Video and IGTV
title: Optional[str] = ""
Expand All @@ -169,7 +163,7 @@ class MediaXma(BaseModel):
preview_media_fbid: Optional[str] = None


class MediaOembed(BaseModel):
class MediaOembed(TypesBaseModel):
title: str
author_name: str
author_url: str
Expand All @@ -187,14 +181,14 @@ class MediaOembed(BaseModel):
can_view: bool


class Collection(BaseModel):
class Collection(TypesBaseModel):
id: str
name: str
type: str
media_count: int


class Comment(BaseModel):
class Comment(TypesBaseModel):
pk: str
text: str
user: UserShort
Expand All @@ -206,22 +200,22 @@ class Comment(BaseModel):
like_count: Optional[int] = None


class Hashtag(BaseModel):
class Hashtag(TypesBaseModel):
id: str
name: str
media_count: Optional[int] = None
profile_pic_url: Optional[HttpUrl] = None


class StoryMention(BaseModel):
class StoryMention(TypesBaseModel):
user: UserShort
x: Optional[float] = None
y: Optional[float] = None
width: Optional[float] = None
height: Optional[float] = None


class StoryMedia(BaseModel):
class StoryMedia(TypesBaseModel):
# Instagram does not return the feed_media object when requesting story,
# so you will have to make an additional request to get media and this is overhead:
# media: Media
Expand All @@ -241,30 +235,30 @@ class StoryMedia(BaseModel):
media_code: Optional[str] = None


class StoryHashtag(BaseModel):
class StoryHashtag(TypesBaseModel):
hashtag: Hashtag
x: Optional[float] = None
y: Optional[float] = None
width: Optional[float] = None
height: Optional[float] = None


class StoryLocation(BaseModel):
class StoryLocation(TypesBaseModel):
location: Location
x: Optional[float] = None
y: Optional[float] = None
width: Optional[float] = None
height: Optional[float] = None


class StoryStickerLink(BaseModel):
class StoryStickerLink(TypesBaseModel):
url: HttpUrl
link_title: Optional[str] = None
link_type: Optional[str] = None
display_url: Optional[str] = None


class StorySticker(BaseModel):
class StorySticker(TypesBaseModel):
id: Optional[str] = None
type: Optional[str] = "gif"
x: float
Expand All @@ -277,14 +271,14 @@ class StorySticker(BaseModel):
extra: Optional[dict] = {}


class StoryBuild(BaseModel):
class StoryBuild(TypesBaseModel):
mentions: List[StoryMention]
path: FilePath
paths: List[FilePath] = []
stickers: List[StorySticker] = []


class StoryLink(BaseModel):
class StoryLink(TypesBaseModel):
webUri: HttpUrl
x: float = 0.5126011
y: float = 0.5168225
Expand All @@ -294,7 +288,7 @@ class StoryLink(BaseModel):
rotation: float = 0.0


class Story(BaseModel):
class Story(TypesBaseModel):
pk: str
id: str
code: str
Expand All @@ -314,15 +308,15 @@ class Story(BaseModel):
medias: List[StoryMedia] = []


class Guide(BaseModel):
class Guide(TypesBaseModel):
id: Optional[str] = None
title: Optional[str] = None
description: str
cover_media: Media
feedback_item: Optional[dict] = None


class DirectMedia(BaseModel):
class DirectMedia(TypesBaseModel):
id: str
media_type: int
user: Optional[UserShort] = None
Expand All @@ -331,7 +325,7 @@ class DirectMedia(BaseModel):
audio_url: Optional[HttpUrl] = None


class ReplyMessage(BaseModel):
class ReplyMessage(TypesBaseModel):
id: str
user_id: Optional[str] = None
timestamp: datetime
Expand All @@ -352,7 +346,7 @@ class ReplyMessage(BaseModel):
placeholder: Optional[dict] = None


class DirectMessage(BaseModel):
class DirectMessage(TypesBaseModel):
id: str # e.g. 28597946203914980615241927545176064
user_id: Optional[str] = None
thread_id: Optional[int] = None # e.g. 340282366841710300949128531777654287254
Expand All @@ -376,13 +370,13 @@ class DirectMessage(BaseModel):
placeholder: Optional[dict] = None


class DirectResponse(BaseModel):
class DirectResponse(TypesBaseModel):
unseen_count: Optional[int] = None
unseen_count_ts: Optional[int] = None
status: Optional[str] = None


class DirectShortThread(BaseModel):
class DirectShortThread(TypesBaseModel):
id: str
users: List[UserShort]
named: bool
Expand All @@ -393,7 +387,7 @@ class DirectShortThread(BaseModel):
is_group: bool


class DirectThread(BaseModel):
class DirectThread(TypesBaseModel):
pk: str # thread_v2_id, e.g. 17898572618026348
id: str # thread_id, e.g. 340282366841510300949128268610842297468
messages: List[DirectMessage]
Expand Down Expand Up @@ -437,7 +431,7 @@ def is_seen(self, user_id: str):
return not any(timestamps)


class Relationship(BaseModel):
class Relationship(TypesBaseModel):
user_id: str
blocking: bool
followed_by: bool
Expand All @@ -452,7 +446,7 @@ class Relationship(BaseModel):
outgoing_request: bool


class RelationshipShort(BaseModel):
class RelationshipShort(TypesBaseModel):
user_id: str
following: bool
incoming_request: bool
Expand All @@ -463,7 +457,7 @@ class RelationshipShort(BaseModel):
outgoing_request: bool


class Highlight(BaseModel):
class Highlight(TypesBaseModel):
pk: str # 17895485401104052
id: str # highlight:17895485401104052
latest_reel_media: int
Expand All @@ -477,12 +471,12 @@ class Highlight(BaseModel):
items: List[Story] = []


class Share(BaseModel):
class Share(TypesBaseModel):
pk: str
type: str


class Track(BaseModel):
class Track(TypesBaseModel):
id: str
title: str
subtitle: str
Expand All @@ -506,7 +500,7 @@ class Track(BaseModel):
territory_validity_periods: dict


class Note(BaseModel):
class Note(TypesBaseModel):
id: str
text: str
user_id: str
Expand Down

0 comments on commit 3f6c91e

Please sign in to comment.