Skip to content

Commit

Permalink
sources.telegram_new: initial module via HPI
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Feb 21, 2023
1 parent 1cc1c78 commit 03b3ab1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/promnesia/sources/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def make_query(text_query: str) -> str:
, snd.display_name AS sender
, M.time AS time
, {text_query} AS text
, M.id AS mid
, M.message_id AS mid
FROM messages AS M
/* chat types are 'dialog' (1-1), 'group' and 'supergroup' */
/* this is abit hacky way to handle all groups in one go */
Expand Down
38 changes: 38 additions & 0 deletions src/promnesia/sources/telegram_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from urllib.parse import unquote # TODO mm, make it easier to rememember to use...

from promnesia.common import Results, logger, extract_urls, Visit, Loc


def index() -> Results:
from . import hpi
from my.telegram.telegram_backup import messages

# TODO port from old module
# TODO - http_only
# TODO - text_query and handling json column
for i, m in enumerate(messages()):
text = m.text

urls = extract_urls(text)
if len(urls) == 0:
continue

dt = m.time
sender = m.sender.name
chat = m.chat

cname = chat.name if chat.name is not None else str(chat.id)

locator = Loc.make(
title=f"chat with {cname}",
href=m.permalink,
)
context = f'{sender}: {text}'

for u in urls:
yield Visit(
url=unquote(u),
dt=dt,
context=context,
locator=locator,
)

0 comments on commit 03b3ab1

Please sign in to comment.