Skip to content

Commit 4b05382

Browse files
authored
OD-1666: Change Tags export to only export Tags used on works (#89)
1 parent 3e0383a commit 4b05382

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

03-Export-Tags-Authors-Stories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def write_csv(data, filename, columns):
5151
cols["ao3_tag_category"],
5252
cols["original_description"],
5353
"TW Notes",
54+
"Used in Archive?",
5455
],
5556
)
5657

shared_python/Tags.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,24 @@ def distinct_tags(self, database):
141141
database,
142142
"""
143143
SELECT DISTINCT
144-
id as "Original Tag ID",
145-
original_tag as "Original Tag Name",
146-
original_type as "Original Tag Type",
147-
original_parent as "Original Parent Tag",
148-
ao3_tag_fandom as "Related Fandom",
149-
ao3_tag as "Recommended AO3 Tag",
150-
ao3_tag_type as "Recommended AO3 Type",
151-
ao3_tag_category as "Recommended AO3 Category",
152-
original_description as "Original Description",
153-
'' as "TW Notes" FROM tags
144+
t.id as "Original Tag ID",
145+
t.original_tag as "Original Tag Name",
146+
t.original_type as "Original Tag Type",
147+
t.original_parent as "Original Parent Tag",
148+
t.ao3_tag_fandom as "Related Fandom",
149+
t.ao3_tag as "Recommended AO3 Tag",
150+
t.ao3_tag_type as "Recommended AO3 Type",
151+
t.ao3_tag_category as "Recommended AO3 Category",
152+
t.original_description as "Original Description",
153+
'' as "TW Notes",
154+
CASE
155+
WHEN EXISTS (
156+
SELECT 1 FROM item_tags it
157+
WHERE it.tag_id = t.id AND it.item_type = 'story'
158+
) THEN "Yes"
159+
ELSE "No"
160+
END AS "Used in Archive?"
161+
FROM tags t
154162
""",
155163
)
156164

@@ -206,7 +214,7 @@ def update_tag_row(self, row: dict):
206214
new_tag_id = sql_dict[0]["LAST_INSERT_ID()"]
207215
# get all associated items from item_tags
208216
items = self.sql.execute_dict(
209-
f"""SELECT item_id, item_type
217+
f"""SELECT item_id, item_type
210218
FROM item_tags WHERE tag_id = {row['Original Tag ID']}"""
211219
)
212220

0 commit comments

Comments
 (0)