2023-01-03 05:52:59 +00:00
|
|
|
from pydantic import BaseModel, AnyHttpUrl
|
2023-01-03 07:54:57 +00:00
|
|
|
from sqlmodel import Field, SQLModel, Relationship
|
2023-01-03 05:52:59 +00:00
|
|
|
from datetime import datetime
|
2023-01-03 07:54:57 +00:00
|
|
|
from typing import Optional, List, TYPE_CHECKING
|
2023-01-03 05:52:59 +00:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
2023-01-03 07:54:57 +00:00
|
|
|
from diyalgo.models.links import EmojiAccountLink, EmojiStatusLink
|
2023-01-03 05:52:59 +00:00
|
|
|
|
2023-01-03 07:54:57 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from diyalgo.models import Status
|
|
|
|
from diyalgo.models import CustomEmoji
|
2023-01-03 05:52:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Account(SQLModel, table=True):
|
|
|
|
"""https://docs.joinmastodon.org/entities/Account/"""
|
|
|
|
id: int = Field(primary_key=True)
|
|
|
|
acct: str
|
|
|
|
avatar: str
|
|
|
|
avatar_static: str
|
|
|
|
bot: bool
|
2023-01-03 07:54:57 +00:00
|
|
|
# created_at:datetime
|
2023-01-03 05:52:59 +00:00
|
|
|
discoverable:bool
|
|
|
|
display_name:str
|
2023-01-03 07:54:57 +00:00
|
|
|
emojis: List['CustomEmoji'] = Relationship(back_populates='accounts', link_model=EmojiAccountLink)
|
|
|
|
# fields: List["AccountField"] = Relationship(back_populates='account')
|
2023-01-03 05:52:59 +00:00
|
|
|
followers_count:int
|
|
|
|
following_count:int
|
|
|
|
group: bool
|
|
|
|
header: str
|
2023-01-03 07:54:57 +00:00
|
|
|
# last_status_at: Optional[datetime] = None
|
2023-01-03 05:52:59 +00:00
|
|
|
limited: Optional[bool] = None
|
|
|
|
locked: bool
|
2023-01-03 07:54:57 +00:00
|
|
|
# moved: Optional['Account'] = Relationship()
|
2023-01-03 05:52:59 +00:00
|
|
|
noindex: Optional[bool] = None
|
|
|
|
header_static: str
|
|
|
|
note: str
|
2023-01-03 07:54:57 +00:00
|
|
|
statuses: List['Status'] = Relationship(back_populates='account')
|
2023-01-03 05:52:59 +00:00
|
|
|
statuses_count: int
|
|
|
|
suspended: Optional[bool] = None
|
|
|
|
url: AnyHttpUrl
|
|
|
|
username: str
|
|
|
|
|
2023-01-03 07:54:57 +00:00
|
|
|
# class Config:
|
|
|
|
# extra = 'ignore'
|
|
|
|
|
|
|
|
class AccountField(SQLModel):
|
|
|
|
id: Optional[int] = Field(primary_key=True, default=None)
|
|
|
|
name: str
|
|
|
|
value: str
|
|
|
|
# verified_at: Optional[datetime] = None
|
|
|
|
# url: Optional[AnyHttpUrl] = None
|
|
|
|
|
|
|
|
account_id: Optional[int] = Field(default=None, foreign_key='account.id')
|
|
|
|
account: Account = Relationship(back_populates='fields')
|
|
|
|
|
|
|
|
# def __init__(self, value:str, **kwargs):
|
|
|
|
# soup = BeautifulSoup(value, 'lxml')
|
|
|
|
# a = soup.find('a')
|
|
|
|
# if a is not None:
|
|
|
|
# url = a.get('href')
|
|
|
|
# else:
|
|
|
|
# url = None
|
|
|
|
# super().__init__(value=value, url=url, **kwargs)
|
|
|
|
#
|
|
|
|
# class Config:
|
|
|
|
# extra = "ignore"
|
|
|
|
|