Skip to content

Commit

Permalink
Handle no article for SoF item
Browse files Browse the repository at this point in the history
  • Loading branch information
mheguy committed Aug 4, 2024
1 parent 668c628 commit c89abf8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions transcription_bot/episode_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class ScienceOrFictionItem:
number: int
show_notes_text: str
article_url: str
article_url: str | None
sof_result: str

article_title: str | None
Expand Down Expand Up @@ -602,17 +602,19 @@ def process_raw_items(raw_items: list["Tag"]) -> list[ScienceOrFictionItem]:

answer = find_single_element(raw_item, "span", "quiz__answer").text

a_tag = find_single_element(p_tag, "a", None)
url = a_tag.get("href", "")

if not isinstance(url, str):
raise TypeError("Got an unexpected type in url")
try:
a_tag = find_single_element(p_tag, "a", None)
article_url = a_tag.get("href", "")
if not isinstance(article_url, str):
raise TypeError("Got an unexpected type in url")
except ValueError:
article_url = ""

publication = None
article_title = None
if url:
publication = urlparse(url).netloc
article_title = get_article_title(url)
if article_url:
publication = urlparse(article_url).netloc
article_title = get_article_title(article_url)

if answer.lower() == "science":
sof_result = f"science{science_items}"
Expand All @@ -624,7 +626,7 @@ def process_raw_items(raw_items: list["Tag"]) -> list[ScienceOrFictionItem]:
ScienceOrFictionItem(
number=item_number,
show_notes_text=p_text,
article_url=url,
article_url=article_url,
sof_result=sof_result,
article_publication=publication,
article_title=article_title,
Expand Down

0 comments on commit c89abf8

Please sign in to comment.