fix: tag export functionality

This commit is contained in:
thomasabishop 2025-01-17 17:48:04 +00:00
parent 2209fbeb54
commit c42ee2eb28
4 changed files with 18 additions and 17 deletions

Binary file not shown.

View file

@ -1,14 +1,14 @@
from setuptools import find_packages, setup # from setuptools import find_packages, setup
setup( # setup(
name="eolas-db", # name="eolas-db",
version="0.1", # version="0.1",
packages=find_packages(where="src"), # packages=find_packages(where="src"),
package_dir={"": "src"}, # package_dir={"": "src"},
install_requires=["python-frontmatter", "termcolor"], # install_requires=["python-frontmatter", "termcolor"],
entry_points={ # entry_points={
"console_scripts": [ # "console_scripts": [
"eolas-db=cli:main", # "eolas-db=cli:main",
], # ],
}, # },
) # )

View file

@ -21,7 +21,6 @@ class DatabaseService:
print(colored("INFO Created database directory", "blue")) print(colored("INFO Created database directory", "blue"))
self.connection = sqlite3.connect(f"{self.db_path}/{self.db_name}.db") self.connection = sqlite3.connect(f"{self.db_path}/{self.db_name}.db")
self.connection.execute("PRAGMA foreign_keys = ON") self.connection.execute("PRAGMA foreign_keys = ON")
print(colored("INFO Database connection established", "blue"))
return self.connection return self.connection
except Exception as e: except Exception as e:

View file

@ -1,3 +1,5 @@
import json
from services.sqlite_service import SqliteService from services.sqlite_service import SqliteService
@ -7,12 +9,12 @@ class TagService(SqliteService):
def __retrieve_entries_for_tag(self, tag): def __retrieve_entries_for_tag(self, tag):
entries = self._query("SELECT * FROM entries_tags WHERE tag_name = ?", (tag,)) entries = self._query("SELECT * FROM entries_tags WHERE tag_name = ?", (tag,))
return sorted([entry[0] for entry in entries]) return sorted([entry[0] for entry in entries], key=str.lower)
def export_tags(self): def export_tags(self):
tags = self._query("SELECT * FROM tags") tags = self._query("SELECT * FROM tags")
tags = sorted([tag[0] for tag in tags]) tags = sorted([tag[0] for tag in tags], key=str.lower)
tag_dict = {} tag_dict = {}
for tag in tags: for tag in tags:
tag_dict[tag] = self.__retrieve_entries_for_tag(tag) tag_dict[tag] = self.__retrieve_entries_for_tag(tag)
return tag_dict print(json.dumps(tag_dict))