my.fbmessenger.export: remove legacy dump_chat_history code
This commit is contained in:
parent
0a05b27266
commit
bef832cbff
1 changed files with 0 additions and 31 deletions
|
@ -9,7 +9,6 @@ REQUIRES = [
|
||||||
|
|
||||||
from contextlib import ExitStack, contextmanager
|
from contextlib import ExitStack, contextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
from my.core import PathIsh, Res, stat, Stats
|
from my.core import PathIsh, Res, stat, Stats
|
||||||
|
@ -59,33 +58,3 @@ def messages() -> Iterator[Res[messenger.Message]]:
|
||||||
|
|
||||||
def stats() -> Stats:
|
def stats() -> Stats:
|
||||||
return stat(messages)
|
return stat(messages)
|
||||||
|
|
||||||
|
|
||||||
### vvv not sure if really belongs here...
|
|
||||||
|
|
||||||
def _dump_helper(model: messenger.DAL, tdir: Path) -> None:
|
|
||||||
for t in model.iter_threads():
|
|
||||||
name = t.name.replace('/', '_') # meh..
|
|
||||||
path = tdir / (name + '.txt')
|
|
||||||
with path.open('w') as fo:
|
|
||||||
for m in t.iter_messages(order_by='-timestamp'):
|
|
||||||
# TODO would be nice to have usernames perhaps..
|
|
||||||
dts = m.dt.strftime('%Y-%m-%d %a %H:%M')
|
|
||||||
msg = f"{dts}: {m.text}"
|
|
||||||
print(msg, file=fo)
|
|
||||||
|
|
||||||
|
|
||||||
def dump_chat_history(where: PathIsh) -> None:
|
|
||||||
p = Path(where)
|
|
||||||
assert not p.exists() or p.is_dir()
|
|
||||||
|
|
||||||
from shutil import rmtree
|
|
||||||
from tempfile import TemporaryDirectory
|
|
||||||
with TemporaryDirectory() as tdir, _dal() as model:
|
|
||||||
td = Path(tdir)
|
|
||||||
_dump_helper(model, td)
|
|
||||||
|
|
||||||
if p.exists():
|
|
||||||
rmtree(p)
|
|
||||||
td.rename(p)
|
|
||||||
td.mkdir() # ugh, hacky way of preventing complaints from context manager
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue