diff --git a/poems/objects.py b/poems/objects.py index fff3593..3bde339 100644 --- a/poems/objects.py +++ b/poems/objects.py @@ -128,7 +128,7 @@ def __repr__(self): @property def translator(self) -> str: - return self.metadata["translator"] if "translator" in self.metadata else None + return self.metadata["translator"] if "translator" in self.metadata else "" @property def keywords(self) -> dict: @@ -144,7 +144,7 @@ def title_by_author(self): @property def pretty_date(self): if "date" not in self.metadata: - return None + return "" year, m, day = [self.metadata["date"].get(attr) for attr in ["year", "month", "day"]] x = "" if m: @@ -165,7 +165,7 @@ def spacetime(self): parts.append(self.metadata["location"]) if self.pretty_date: parts.append(self.pretty_date) - return ". ".join(parts) or None + return ". ".join(parts) or "" @property def test_email_subject(self): @@ -175,6 +175,16 @@ def test_email_subject(self): def daily_email_subject(self): return f"Poem of the Day: {self.title_by_author}" + @property + def html_description(self): + + if self.author.name: + description = f'{self.title} by {self.author.name} {self.author.dates.replace("--", "–")}' + else: + description = self.title + + return description + @property def html_body(self): body_text = self.body.replace("--", "—") # convert emdashes @@ -200,12 +210,14 @@ def html_body(self): return "\n".join(parsed_lines) - @property - def html_date(self): - return f'
{self.context.pretty_date}
' + # @property + # def html_date(self): + # return f'
{self.context.pretty_date}
' + + @property - def html_description(self): + def email_header(self): if self.author.name: description = f'
{self.title} by {self.author.name} {self.author.dates.replace("--", "–")}
' @@ -223,7 +235,7 @@ def email_html(self):
-{self.html_description} +{self.email_header}
{self.html_body} diff --git a/scripts/send-poem.py b/scripts/send-poem.py index ba592ad..6c49ff1 100644 --- a/scripts/send-poem.py +++ b/scripts/send-poem.py @@ -72,21 +72,12 @@ def thread_process(poem, username, password, name, email, subject): packet = { "date": p.context.pretty_date, - "author": { - "name": p.author.name, - "link": p.author.link, - "dates": p.author.dates.replace("--", "–") - }, - "title": p.title, + "description": p.html_description, "body": p.html_body, + "translation": f"Translated by {p.translator}" if p.translator else "", + "spacetime": p.spacetime } - if p.spacetime: - packet["spacetime"] = p.spacetime - - if p.translator: - packet["translator"] = p.translator - daily_poems[str(index)] = packet except Exception as e: