From bd5da6214b1d395d254562c3d5022fd31bf8a08e Mon Sep 17 00:00:00 2001 From: Harlan Lieberman-Berg Date: Sat, 16 Mar 2024 22:06:03 -0400 Subject: [PATCH] Add check for stories without any chapters. Thanks, @minjonet, for the idea! --- 08-Check-ODAP-Tables.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/08-Check-ODAP-Tables.py b/08-Check-ODAP-Tables.py index 7ffec17..8f6b0fd 100755 --- a/08-Check-ODAP-Tables.py +++ b/08-Check-ODAP-Tables.py @@ -211,4 +211,24 @@ log.error("Found at least one bad author email; ending audit here.") sys.exit(7) + ## + ## Check for stories without chapters + ## + + log.debug("Checking for stories without any chapters.") + found_error = False + + empty_stories = sql.execute_dict( + "SELECT s.id as sid FROM stories s LEFT JOIN chapters c ON c.story_id = s.id WHERE c.story_id IS NULL" + ) + + if empty_stories: + found_error = True + for story in empty_stories: + log.error(f"Found story with no chapters: {story['sid']}") + + if found_error: + log.error("Found at least one story with no chapters; ending audit here.") + sys.exit(8) + log.info("All checks completed successfully.")