my.bumble: merge from all previous android exports

This commit is contained in:
Dima Gerasimov 2022-06-02 13:42:33 +01:00 committed by karlicoss
parent b96c9f4534
commit fd1a683d49
2 changed files with 51 additions and 32 deletions

View file

@ -7,6 +7,7 @@ from dataclasses import dataclass
from datetime import datetime
from typing import Iterator, Sequence, Optional, Dict
from more_itertools import unique_everseen
from my.config import bumble as user_config
@ -53,12 +54,19 @@ class Message(_BaseMessage):
import json
from typing import Union
from ..core.error import Res
from ..core import Res
import sqlite3
from ..core.sqlite import sqlite_connect_immutable
def _entities() -> Iterator[Res[Union[Person, _Message]]]:
last = max(inputs()) # TODO -- need to merge multiple?
with sqlite_connect_immutable(last) as db:
EntitiesRes = Res[Union[Person, _Message]]
def _entities() -> Iterator[EntitiesRes]:
for db_file in inputs():
with sqlite_connect_immutable(db_file) as db:
yield from _handle_db(db)
def _handle_db(db) -> Iterator[EntitiesRes]:
for row in db.execute(f'SELECT user_id, user_name FROM conversation_info'):
(user_id, user_name) = row
yield Person(
@ -89,10 +97,20 @@ def _entities() -> Iterator[Res[Union[Person, _Message]]]:
yield e
def _key(r: EntitiesRes):
if isinstance(r, _Message):
if '&srv_width=' in r.text:
# ugh. seems that image URLs change all the time in the db?
# can't access them without login anyway
# so use a different key for such messages
return (r.id, r.created)
return r
def messages() -> Iterator[Res[Message]]:
id2person: Dict[str, Person] = {}
id2msg: Dict[str, Message] = {}
for x in _entities():
for x in unique_everseen(_entities(), key=_key):
if isinstance(x, Exception):
yield x
continue

View file

@ -139,6 +139,7 @@ commands =
-p my.coding.commits \
-p my.goodreads \
-p my.pdfs \
-p my.bumble.android \
--txt-report .coverage.mypy-misc \
--html-report .coverage.mypy-misc \
{posargs}