Skip to content

Commit

Permalink
less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed Jul 31, 2023
1 parent 19baa43 commit 05c2b1b
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 38 deletions.
13 changes: 6 additions & 7 deletions poems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Author():
@property
def dates(self) -> str:
if self.death is None:
return f"(born {self.birth})"
return f"(b. {self.birth})"
if self.birth < 0:
if self.death < 0:
return f"({(-self.birth)} BC &#8211; {-self.death} BC)"
Expand All @@ -53,6 +53,7 @@ def dates(self) -> str:

@dataclass
class Poem():
"""Poem data class"""
author: Author
title: str
body: str
Expand Down Expand Up @@ -201,7 +202,6 @@ def get_poem(
context=None,
weight_schemes=["context"],
forced_contexts=[],
historical_tag=None,
verbose=True,
very_verbose=False,
**kwargs,
Expand Down Expand Up @@ -316,8 +316,8 @@ def get_poem(

self.poems["probability"] = self.poems.likelihood / self.poems.likelihood.sum()
if very_verbose:
print(f"choosing from {len(self.poems)} poems. the 10 most likely are:")
print(self.poems.sort_values("probability", ascending=False)[["author","title","keywords","probability"]].iloc[:10])
print(f"choosing from {len(self.poems)} poems; the 20 most likely are:")
print(self.poems.sort_values("probability", ascending=False)[["author","title","keywords","probability"]].iloc[:20])
chosen_loc = np.random.choice(self.poems.index, p=self.poems.probability)
chosen_author, chosen_title = self.poems.loc[chosen_loc, ["author", "title"]]

Expand All @@ -328,9 +328,8 @@ def get_poem(
**POEMS[chosen_author]["poems"][chosen_title],
when=self.when)

if not historical_tag is None:
now = datetime.now(tz=pytz.utc)
self.history.loc[len(self.history)+1] = chosen_author, chosen_title, *now.isoformat()[:19].split("T"), int(now.timestamp())
now = datetime.now(tz=pytz.utc)
self.history.loc[len(self.history)+1] = chosen_author, chosen_title, *now.isoformat()[:19].split("T"), int(now.timestamp())

return poem

Expand Down
135 changes: 125 additions & 10 deletions poems/poems.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion poems/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def get_holiday(t=None):
if (month, day) == (2, 2): return "candlemas"
if (month, day) == (2, 11): return "our_lady_of_lourdes"
if (month, day) == (2, 14): return "saint_valentine"
if (month, day) == (2, 29): return "leap_day"

if (month, day) == (3, 17): return "saint_patrick"
if (month, day) == (3, 19): return "saint_joseph"
Expand All @@ -103,6 +104,7 @@ def get_holiday(t=None):
if (month, day) == (5, 31): return "visitation"

if (month, day) == (6, 19): return "juneteenth"
if (month, day) == (6, 23): return "saint_johns_eve"
if (month, day) == (6, 24): return "saint_john_the_baptist"
if (month, day) == (6, 29): return "saints_peter_and_paul"

Expand All @@ -128,7 +130,7 @@ def get_holiday(t=None):
if (month, day) == (9, 15): return "our_lady_of_sorrows"
if (month, day) == (9, 19): return "our_lady_of_la_salette"
if (month, day) == (9, 21): return "saint_matthew"
if (month, day) == (9, 29): return "saint_michael"
if (month, day) == (9, 29): return "michaelmas"
if (month, day) == (9, 30): return "saint_jerome"

if (month, day) == (10, 1): return "saint_therese_of_lisieux"
Expand Down
10 changes: 6 additions & 4 deletions poems/weights.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"holiday": {
"new_years_day": 365.242,
"none": 1.321,
"none": 1.327,
"epiphany": 365.242,
"saint_agnes_eve": 365.242,
"saint_agnes": 365.242,
Expand All @@ -82,12 +82,13 @@
"ash_wednesday": 365.242,
"our_lady_of_lourdes": 394.857,
"saint_valentine": 390.634,
"leap_day": 1605.462,
"palm_sunday": 365.242,
"saint_patrick": 366.158,
"holy_thursday": 365.242,
"saint_joseph": 379.473,
"spring_equinox": 410.385,
"holy_thursday": 365.242,
"good_friday": 365.242,
"spring_equinox": 410.385,
"holy_saturday": 365.242,
"easter_sunday": 365.242,
"annunciation": 427.184,
Expand All @@ -107,6 +108,7 @@
"fathers_day": 493.571,
"juneteenth": 391.681,
"summer_solstice": 457.984,
"saint_johns_eve": 385.48,
"saint_john_the_baptist": 385.48,
"saints_peter_and_paul": 374.608,
"saint_thomas_the_apostle": 365.242,
Expand All @@ -131,7 +133,7 @@
"our_lady_of_la_salette": 365.242,
"saint_matthew": 365.242,
"autumn_equinox": 367.078,
"saint_michael": 365.242,
"michaelmas": 365.242,
"saint_jerome": 365.242,
"saint_therese_of_lisieux": 365.242,
"saint_francis": 365.242,
Expand Down
4 changes: 2 additions & 2 deletions scripts/make-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def commit_elements(elements):
except:
contents = None
if html != contents:
print(f'OVERWRITE #{index:>03} {y}/{m}/{d} {entry.author:>26} {poem.title}')
print(f'OVERWRITE #{index:>03} {y}/{m}/{d} {poem.author.name:>26} {poem.title}')
else:
print(f' #{index:>03} {y}/{m}/{d} {entry.author:>26} {poem.title}')
print(f' #{index:>03} {y}/{m}/{d} {poem.author.name:>26} {poem.title}')
continue

blob = curator.repo.create_git_blob(html, "utf-8")
Expand Down
25 changes: 11 additions & 14 deletions scripts/send-poem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
curator = poems.Curator()
curator.load_github_repo(github_repo_name=args.github_repo_name, github_token=args.github_token)

if args.kind == "test":
test = (args.kind == "test")
if test:
curator.read_history(filename="data/poems/history-test.csv", from_repo=True)
elif args.kind == "daily":
curator.read_history(filename="data/poems/history-daily.csv", from_repo=True)
else:
raise Exception(f"unhandled kind f{args.kind}")

when = ttime.time() if not args.kind == "test" else ttime.time() + 365 * 86400 * np.random.uniform()
when = ttime.time() if not test else ttime.time() + 365 * 86400 * np.random.uniform()

context = poems.utils.get_context(when)

Expand All @@ -36,19 +39,14 @@
context=context,
weight_schemes=["context", "history"],
forced_contexts=FORCED_CONTEXTS,
historical_tag=args.kind,
very_verbose=True,
verbose=True,
very_verbose=test,
)

if args.kind == "test":
if test:
subject = f"(TEST) {curated_poem.nice_fancy_date}: {curated_poem.header} {curated_poem.keywords}"
elif args.kind == "daily":
subject = f"Poem of the Day: {curated_poem.header}"
else:
raise Exception("unhandled kind")

if args.listserv_filename == "":
raise Exception("could not find a listserv")
subject = f"Poem of the Day: {curated_poem.header}"

contents = curator.repo.get_contents(args.listserv_filename, ref="master")
entries = pd.read_csv(StringIO(contents.decoded_content.decode()), index_col=0)
Expand All @@ -69,11 +67,10 @@ def thread_process(poem, username, password, name, email, subject):
t = threading.Thread(target=thread_process, args=(curated_poem, args.username, args.password, name, email, subject))
t.start()


if args.kind == "test":
if test:
curator.write_to_repo(items={"data/poems/history-test.csv" : curator.history.to_csv()}, verbose=True)

if args.kind == "daily":
else:
curator.write_to_repo(items={"data/poems/history-daily.csv" : curator.history.to_csv(),
"data/poems/author-stats.csv" : curator.stats.drop(columns=["days_since_last_sent"]).to_csv()}, verbose=True)

Expand Down

0 comments on commit 05c2b1b

Please sign in to comment.