2023-05-25 09:37:27 +00:00
|
|
|
from datetime import datetime, timedelta
|
2023-05-24 15:20:21 +00:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
2024-02-17 05:50:20 +00:00
|
|
|
from httpx import URL
|
2023-05-24 15:20:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Tweet(BaseModel):
|
|
|
|
content: str
|
2024-02-17 05:50:20 +00:00
|
|
|
old_url: str
|
2023-05-24 15:20:21 +00:00
|
|
|
time: datetime
|
|
|
|
images: List[str]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self) -> int:
|
2024-02-17 05:50:20 +00:00
|
|
|
tid = self.url.split("/")[-1].replace("#m", "")
|
|
|
|
return int(tid)
|
2023-05-24 15:20:21 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def time_str(self) -> str:
|
2023-05-25 09:37:27 +00:00
|
|
|
utc_8_time = self.time + timedelta(hours=8)
|
|
|
|
return utc_8_time.strftime("%Y-%m-%d %H:%M:%S")
|
2023-05-24 15:20:21 +00:00
|
|
|
|
2024-02-17 05:50:20 +00:00
|
|
|
@property
|
|
|
|
def url(self) -> str:
|
|
|
|
u = URL(self.old_url)
|
|
|
|
return self.old_url.replace(u.host, "twitter.com")
|
|
|
|
|
2023-05-24 15:20:21 +00:00
|
|
|
|
|
|
|
class User(BaseModel):
|
|
|
|
username: str
|
|
|
|
name: str
|
|
|
|
tweets: List[Tweet]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def link(self) -> str:
|
|
|
|
return f"https://twitter.com/{self.username}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def format(self) -> str:
|
|
|
|
return f'<a href="{self.link}">{self.name}</a>'
|