From f6c9b910f58219294cbe472a58a66be1bd09dd05 Mon Sep 17 00:00:00 2001 From: TAJSchaaf <157992880+TAJSchaaf@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:56:20 +0200 Subject: [PATCH 1/2] OD-1666: Change Tags export to only export Tags used on works - Introduces a 'Used in Archive?' column to the tag export, indicating whether each tag is used in any story. - Updates SQL query and output columns to support this feature. --- 03-Export-Tags-Authors-Stories.py | 1 + shared_python/Tags.py | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/03-Export-Tags-Authors-Stories.py b/03-Export-Tags-Authors-Stories.py index 9b5a6eb..8929048 100755 --- a/03-Export-Tags-Authors-Stories.py +++ b/03-Export-Tags-Authors-Stories.py @@ -51,6 +51,7 @@ def write_csv(data, filename, columns): cols["ao3_tag_category"], cols["original_description"], "TW Notes", + "Used in Archive?" ], ) diff --git a/shared_python/Tags.py b/shared_python/Tags.py index 1dc780c..6f680fb 100755 --- a/shared_python/Tags.py +++ b/shared_python/Tags.py @@ -141,16 +141,24 @@ def distinct_tags(self, database): database, """ SELECT DISTINCT - id as "Original Tag ID", - original_tag as "Original Tag Name", - original_type as "Original Tag Type", - original_parent as "Original Parent Tag", - ao3_tag_fandom as "Related Fandom", - ao3_tag as "Recommended AO3 Tag", - ao3_tag_type as "Recommended AO3 Type", - ao3_tag_category as "Recommended AO3 Category", - original_description as "Original Description", - '' as "TW Notes" FROM tags + t.id as "Original Tag ID", + t.original_tag as "Original Tag Name", + t.original_type as "Original Tag Type", + t.original_parent as "Original Parent Tag", + t.ao3_tag_fandom as "Related Fandom", + t.ao3_tag as "Recommended AO3 Tag", + t.ao3_tag_type as "Recommended AO3 Type", + t.ao3_tag_category as "Recommended AO3 Category", + t.original_description as "Original Description", + '' as "TW Notes", + CASE + WHEN EXISTS ( + SELECT 1 FROM item_tags it + WHERE it.tag_id = t.id AND it.item_type = 'story' + ) THEN "Yes" + ELSE "No" + END AS "Used in Archive?" + FROM tags t """, ) @@ -206,7 +214,7 @@ def update_tag_row(self, row: dict): new_tag_id = sql_dict[0]["LAST_INSERT_ID()"] # get all associated items from item_tags items = self.sql.execute_dict( - f"""SELECT item_id, item_type + f"""SELECT item_id, item_type FROM item_tags WHERE tag_id = {row['Original Tag ID']}""" ) From 3f033a58f9d255659046c52abbb34658abade401 Mon Sep 17 00:00:00 2001 From: TAJSchaaf <157992880+TAJSchaaf@users.noreply.github.com> Date: Sun, 14 Sep 2025 19:51:01 +0200 Subject: [PATCH 2/2] Update 03-Export-Tags-Authors-Stories.py --- 03-Export-Tags-Authors-Stories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03-Export-Tags-Authors-Stories.py b/03-Export-Tags-Authors-Stories.py index 8929048..07776a3 100755 --- a/03-Export-Tags-Authors-Stories.py +++ b/03-Export-Tags-Authors-Stories.py @@ -51,7 +51,7 @@ def write_csv(data, filename, columns): cols["ao3_tag_category"], cols["original_description"], "TW Notes", - "Used in Archive?" + "Used in Archive?", ], )