@@ -70,7 +70,7 @@ def messages_query() -> str:
7070 S.ClientName,
7171 '(' || S.Number || ')' /* contacts have one xor the other, but failsafe */
7272 ) AS sender,
73- coalesce(M.Subject, M.Body) /* didn't see any msg with both */
73+ coalesce(M.Subject, M.Body) /* didn't see any msg with both */
7474 AS text,
7575 M.info AS infojson, /* to harvested titles from embedded urls */
7676 G.PGTags AS tags
@@ -88,39 +88,14 @@ def messages_query() -> str:
8888 )
8989
9090
91- def _ensure_sqlite_hardlink (db_path : Path ) -> Path :
92- """
93- Hard-link user's db to an ``.sqlite`` path, so locator `file://` urls work
94-
95- ... at least in Gnome, where mime-type assumed from the suffix.
96-
97- :returns:
98- the hard-link's path, or the original `db_path` if not a ``.db`` file.
99- :raises:
100- any non ``FileExistsError`` exception while hard-linking.
101- """
102- if db_path .suffix .lower () == ".db" :
103- new_suffix = ".sqlite"
104- sqlite_path = db_path .with_suffix (new_suffix )
105- try :
106- db_path .link_to (sqlite_path )
107- logger .info (
108- "Hard-link db-file (for locator-hrefs): %s --> %s" , db_path , new_suffix
109- )
110- except FileExistsError :
111- logger .debug ("Ok, link already existed: %s --> %s" , db_path , new_suffix )
112- return sqlite_path
113- return db_path
114-
115-
11691def _parse_json_title (js ) -> str :
11792 if js and js .strip ():
11893 js = json .loads (js )
11994 if isinstance (js , dict ):
12095 return js .get ("Title" )
12196
12297
123- def _handle_row (row : dict , sqlite_path : PathLike ) -> Results :
98+ def _handle_row (row : dict , db_path : PathLike ) -> Results :
12499 text = row ["text" ]
125100 urls = extract_urls (text )
126101 if not urls :
@@ -154,7 +129,7 @@ def _handle_row(row: dict, sqlite_path: PathLike) -> Results:
154129 context = text ,
155130 locator = Loc .make (
156131 title = f"chat({ mid } ) from { sender } @{ chatname } " ,
157- href = f"file://{ sqlite_path } #!Messages.EventId={ mid } " ,
132+ href = f"file://{ db_path } #!Messages.EventId={ mid } " ,
158133 ),
159134 )
160135
@@ -176,12 +151,11 @@ def _harvest_db(db_path: PathIsh, msgs_query: str):
176151 # Note: for displaying maybe better not to expand/absolute,
177152 # but it's safer for debugging resolved.
178153 db_path = db_path .resolve ()
179- sqlite_path : Path = _ensure_sqlite_hardlink (db_path )
180154
181155 with _dataset_readonly (db_path ) as db :
182156 for row in db .query (msgs_query ):
183157 try :
184- yield from _handle_row (row , sqlite_path )
158+ yield from _handle_row (row , db_path )
185159 except Exception as ex :
186160 # TODO: also insert errors in db
187161 logger .warning (
@@ -194,13 +168,12 @@ def _harvest_db(db_path: PathIsh, msgs_query: str):
194168
195169
196170def index (db_path : PathIsh = "~/.ViberPC/*/viber.db" ) -> Results :
197- logger .debug ("Expanding path(s): %s" , db_path )
198171 glob_paths = list (_get_files (db_path ))
199- logger .debug ("Expanding path(s): %s" , glob_paths )
172+ logger .debug ("Expanded path(s): %s" , glob_paths )
200173 assert glob_paths , f"No Viber-desktop sqlite found: { db_path } "
201174
202175 msgs_query = messages_query ()
203176
204177 for db_path in _get_files (db_path ):
205- assert db_path .is_file (), f"Is it a (Viber-desktop sqlite) file: { db_path } "
178+ assert db_path .is_file (), f"Is it a (Viber-desktop sqlite) file? { db_path } "
206179 yield from _harvest_db (db_path , msgs_query )
0 commit comments