Skip to content

Commit dd5b73c

Browse files
authored
08: Check for empty/malformed chapters, authors (#79)
1 parent 7501985 commit dd5b73c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

08-Check-ODAP-Tables.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,71 @@
144144
log.error("Found at least one story with too many chapters; ending audit here.")
145145
sys.exit(5)
146146

147+
##
148+
## Check for empty chapters
149+
##
150+
151+
log.debug("Checking for empty chapters.")
152+
found_error = False
153+
154+
empty_chap = sql.execute_dict(
155+
"SELECT id as chap, story_id as sid FROM chapters WHERE text = '' or text = NULL",
156+
)
157+
158+
if empty_chap:
159+
found_error = True
160+
for story in empty_chap:
161+
log.error(
162+
f"Found chapter {story['chap']} in story {story['sid']} that is empty."
163+
)
164+
165+
if found_error:
166+
log.error("Found at least one empty chapter; ending audit here.")
167+
sys.exit(5)
168+
169+
##
170+
## Check for malformed author names
171+
##
172+
173+
log.debug("Checking for malformed author names.")
174+
found_error = False
175+
176+
bad_author = sql.execute_dict(
177+
"SELECT id as au, name FROM authors WHERE name = '' OR name = NULL OR name LIKE '-'"
178+
)
179+
180+
if bad_author:
181+
found_error = True
182+
for author in bad_author:
183+
log.error(
184+
f"Found author {author['au']} with illegal name: '{author['name']}'"
185+
)
186+
187+
if found_error:
188+
log.error("Found at least one bad author name; ending audit here.")
189+
sys.exit(6)
190+
191+
##
192+
## Check for malformed author emails
193+
##
194+
195+
log.debug("Checking for malformed author emails.")
196+
found_error = False
197+
198+
bad_email = sql.execute_dict(
199+
# The two percents are because the string is interpreted as a format-string, but we want the wildcard to make it to SQL itself
200+
"SELECT id as au, email FROM authors WHERE email = '' OR email = NULL OR email LIKE 'mailto:%%'"
201+
)
202+
203+
if bad_email:
204+
found_error = True
205+
for email in bad_email:
206+
log.error(
207+
f"Found author {email['au']} with illegal email address:'{email['email']}'"
208+
)
209+
210+
if found_error:
211+
log.error("Found at least one bad author email; ending audit here.")
212+
sys.exit(7)
213+
147214
log.info("All checks completed successfully.")

0 commit comments

Comments
 (0)