twitter: add permalink to Talon objects; extract shared method
This commit is contained in:
parent
19da373a0a
commit
de7972be05
4 changed files with 30 additions and 14 deletions
|
@ -49,7 +49,7 @@ def inputs() -> Sequence[Path]:
|
|||
return get_files(config.export_path)[-1:]
|
||||
|
||||
|
||||
Tid = str
|
||||
from .common import TweetId, permalink
|
||||
|
||||
|
||||
# TODO make sure it's not used anywhere else and simplify interface
|
||||
|
@ -58,7 +58,7 @@ class Tweet(NamedTuple):
|
|||
screen_name: str
|
||||
|
||||
@property
|
||||
def id_str(self) -> str:
|
||||
def id_str(self) -> TweetId:
|
||||
return self.raw['id_str']
|
||||
|
||||
@property
|
||||
|
@ -68,7 +68,7 @@ class Tweet(NamedTuple):
|
|||
|
||||
@property
|
||||
def permalink(self) -> str:
|
||||
return f'https://twitter.com/{self.screen_name}/status/{self.tid}'
|
||||
return permalink(screen_name=self.screen_name, id=self.id_str)
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
|
@ -92,11 +92,11 @@ class Tweet(NamedTuple):
|
|||
|
||||
# TODO deprecate tid?
|
||||
@property
|
||||
def tid(self) -> Tid:
|
||||
def tid(self) -> TweetId:
|
||||
return self.id_str
|
||||
|
||||
@property
|
||||
def dt(self) -> datetime:
|
||||
def dt(self) -> datetime_aware:
|
||||
return self.created_at
|
||||
|
||||
|
||||
|
@ -104,14 +104,13 @@ class Like(NamedTuple):
|
|||
raw: Json
|
||||
screen_name: str
|
||||
|
||||
# TODO need to make permalink/link/url consistent across my stuff..
|
||||
@property
|
||||
def permalink(self) -> str:
|
||||
# doesn'tseem like link it export is more specific...
|
||||
return f'https://twitter.com/{self.screen_name}/status/{self.tid}'
|
||||
return permalink(screen_name=self.screen_name, id=self.id_str)
|
||||
|
||||
@property
|
||||
def id_str(self) -> Tid:
|
||||
def id_str(self) -> TweetId:
|
||||
return self.raw['tweetId']
|
||||
|
||||
@property
|
||||
|
@ -121,13 +120,14 @@ class Like(NamedTuple):
|
|||
|
||||
# TODO deprecate?
|
||||
@property
|
||||
def tid(self) -> Tid:
|
||||
def tid(self) -> TweetId:
|
||||
return self.id_str
|
||||
|
||||
|
||||
from functools import lru_cache
|
||||
class ZipExport:
|
||||
def __init__(self, archive_path: Path) -> None:
|
||||
# TODO use ZipPath
|
||||
self.epath = archive_path
|
||||
|
||||
self.old_format = False # changed somewhere around 2020.03
|
||||
|
@ -189,3 +189,7 @@ def stats() -> Stats:
|
|||
**stat(tweets),
|
||||
**stat(likes),
|
||||
}
|
||||
|
||||
|
||||
## Deprecated stuff
|
||||
Tid = TweetId
|
||||
|
|
|
@ -8,6 +8,7 @@ from more_itertools import unique_everseen
|
|||
|
||||
# TODO add proper Protocol for Tweet
|
||||
Tweet = Any
|
||||
TweetId = str
|
||||
|
||||
|
||||
from my.core import warn_if_empty, Res
|
||||
|
@ -19,3 +20,7 @@ def merge_tweets(*sources: Iterator[Res[Tweet]]) -> Iterator[Res[Tweet]]:
|
|||
else:
|
||||
return r.id_str
|
||||
yield from unique_everseen(chain(*sources), key=key)
|
||||
|
||||
|
||||
def permalink(*, screen_name: str, id: str) -> str:
|
||||
return f'https://twitter.com/{screen_name}/status/{id}'
|
||||
|
|
|
@ -25,15 +25,21 @@ def inputs() -> Sequence[Path]:
|
|||
return get_files(config.export_path)
|
||||
|
||||
|
||||
from .common import TweetId, permalink
|
||||
|
||||
|
||||
@dataclass(unsafe_hash=True)
|
||||
class Tweet:
|
||||
id_str: str
|
||||
id_str: TweetId
|
||||
created_at: datetime_aware
|
||||
screen_name: str
|
||||
text: str
|
||||
urls: Sequence[str]
|
||||
|
||||
@property
|
||||
def permalink(self) -> str:
|
||||
return permalink(screen_name=self.screen_name, id=self.id_str)
|
||||
|
||||
|
||||
# meh... just wrappers to tell apart tweets from favorites...
|
||||
@dataclass(unsafe_hash=True)
|
||||
|
|
|
@ -35,11 +35,14 @@ def get_db_path() -> Path:
|
|||
return max(get_files(config.export_path))
|
||||
|
||||
|
||||
from .common import TweetId, permalink
|
||||
|
||||
|
||||
class Tweet(NamedTuple):
|
||||
row: Json
|
||||
|
||||
@property
|
||||
def id_str(self) -> str:
|
||||
def id_str(self) -> TweetId:
|
||||
return self.row['id_str']
|
||||
|
||||
@property
|
||||
|
@ -50,7 +53,6 @@ class Tweet(NamedTuple):
|
|||
dt = datetime.fromtimestamp(seconds, tz=tz)
|
||||
return dt
|
||||
|
||||
# TODO permalink -- take user into account?
|
||||
@property
|
||||
def screen_name(self) -> str:
|
||||
return self.row['screen_name']
|
||||
|
@ -66,10 +68,9 @@ class Tweet(NamedTuple):
|
|||
return []
|
||||
return ustr.split(',')
|
||||
|
||||
# TODO move to common
|
||||
@property
|
||||
def permalink(self) -> str:
|
||||
return f'https://twitter.com/{self.screen_name}/status/{self.id_str}'
|
||||
return permalink(screen_name=self.screen_name, id=self.id_str)
|
||||
|
||||
|
||||
# TODO urls
|
||||
|
|
Loading…
Add table
Reference in a new issue