Skip to content

Commit

Permalink
smaller packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed May 8, 2024
1 parent abef737 commit 704e30d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
28 changes: 20 additions & 8 deletions poems/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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 <a href="{self.author.link}">{self.author.name}</a> {self.author.dates.replace("--", "&ndash;")}'
else:
description = self.title

return description

@property
def html_body(self):
body_text = self.body.replace("--", "&#8212;") # convert emdashes
Expand All @@ -200,12 +210,14 @@ def html_body(self):

return "\n".join(parsed_lines)

@property
def html_date(self):
return f'<div><i>{self.context.pretty_date}</i></div>'
# @property
# def html_date(self):
# return f'<div><i>{self.context.pretty_date}</i></div>'



@property
def html_description(self):
def email_header(self):

if self.author.name:
description = f'<div>{self.title} by <a href="{self.author.link}">{self.author.name}</a> {self.author.dates.replace("--", "&ndash;")}</div>'
Expand All @@ -223,7 +235,7 @@ def email_html(self):
<html lang="en">
<section style="text-align: left; max-width: 960px; font-family: Baskerville; font-size: 18px;">
<section style="padding-bottom: 32px;">
{self.html_description}
{self.email_header}
</section>
<section style="padding-bottom: 32px;">
{self.html_body}
Expand Down
15 changes: 3 additions & 12 deletions scripts/send-poem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("--", "&ndash;")
},
"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:
Expand Down

0 comments on commit 704e30d

Please sign in to comment.