42 lines
1000 B
Python
42 lines
1000 B
Python
from pydantic import BaseModel, AnyHttpUrl
|
|
from pydantic import Field as _Field
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
from bs4 import BeautifulSoup
|
|
|
|
class Field(BaseModel):
|
|
name: str
|
|
value: str
|
|
url: Optional[AnyHttpUrl] = None
|
|
|
|
def __init__(self, name:str, value:str):
|
|
soup = BeautifulSoup(value, 'lxml')
|
|
a = soup.find('a')
|
|
if a is not None:
|
|
url = a.get('href')
|
|
else:
|
|
url = None
|
|
super().__init__(name=name, value=value, url=url)
|
|
|
|
class Config:
|
|
extra = "ignore"
|
|
|
|
|
|
class Account(BaseModel):
|
|
"""Not transcribing full model now, just using to check"""
|
|
acct: str
|
|
avatar: str
|
|
avatar_static: str
|
|
bot: bool
|
|
created_at:datetime
|
|
discoverable:bool
|
|
display_name:str
|
|
fields: List[Field] = _Field(default_factory=list)
|
|
followers_count:int
|
|
following_count:int
|
|
id: int
|
|
url: AnyHttpUrl
|
|
username: str
|
|
|
|
class Config:
|
|
extra = 'ignore' |