Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
plandes committed Jan 2, 2024
1 parent b68c916 commit 923c41f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/python/zensols/zotsite/betterbib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import Dict, Any
import logging
import json
from pathlib import Path
import sqlite3
from zensols.persist import persisted
from zensols.zotsite import ZoteroObject, Item, Visitor, Library
Expand All @@ -19,20 +19,25 @@ class BetterBibtexMapper(object):
"""
def __init__(self, lib: Library):
lib_id = lib.library_id
path = lib.data_dir / 'better-bibtex.sqlite'
logger.info(f'reading bibtex DB at {path}')
self.lib = lib

@property
@persisted('_mapping')
def mapping(self) -> Dict[str, Any]:
path: Path = self.lib.data_dir / 'better-bibtex.sqlite'
if logger.isEnabledFor(logging.INFO):
logger.info(f'reading bibtex DB at {path}')
conn = sqlite3.connect(':memory:')
conn.execute('ATTACH DATABASE ? AS betterbibtex', (str(path),))
try:
rows = tuple(conn.execute("""select itemID, citationKey from betterbibtex.`citationkey` where libraryID = ?""", (int(lib_id),)))
self.data = rows
return dict(conn.execute(
"""\
select itemID, citationKey from betterbibtex.`citationkey`
where libraryID = ?""",
[self.lib.library_id]))
finally:
conn.close()
@property
@persisted('_mapping')
def mapping(self) -> Dict[str, Any]:
return {x[0]: x[1] for x in self.data}


class BetterBibtexVisitor(Visitor):
"""Use the ``BetterBibtexMapper`` to change the keys in mapped items to the
Expand Down

0 comments on commit 923c41f

Please sign in to comment.