Skip to content

Commit

Permalink
optional writing to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed Jun 29, 2024
1 parent f55ad50 commit 64e6f57
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hourly-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- name: Curate a poem, and send it to the testserv
run:
python scripts/send-poem.py --kind "test" --username "[email protected]" --password ${{ secrets.PFT_PW }} --listserv_filename "data/poems/testserv.csv"
--github_repo_name "thomaswmorris.github.io" --github_token ${{ secrets.GH_TOKEN }} --write_to_repo false
--github_repo_name "thomaswmorris.github.io" --github_token ${{ secrets.GH_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: Send poem to myself
run:
python scripts/send-poem.py --kind "test" --username "[email protected]" --password ${{ secrets.PFT_PW }} --listserv_filename "data/poems/testserv.csv"
--github_repo_name "thomaswmorris.github.io" --github_token ${{ secrets.GH_TOKEN }} --write_to_repo true
--github_repo_name "thomaswmorris.github.io" --github_token ${{ secrets.GH_TOKEN }} --write_to_repo
6 changes: 6 additions & 0 deletions poems/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def get_holiday(t=None):
return "winter_solstice"

christmas_day = datetime(dt.year,12,25)
christmas_day_weekday = WEEKDAYS[christmas_day.weekday()]
advent_sunday_year_day = christmas_day.timetuple().tm_yday - (22 + christmas_day.weekday())

# these are relative to advent
Expand Down Expand Up @@ -155,6 +156,11 @@ def get_holiday(t=None):
if (month, weekday) == ("may", "monday") and (get_utc_datetime(t + 7 * 86400).month == 6):
return "memorial_day" # last monday of may

if (year_day > christmas_day.timetuple().tm_yday) and (weekday == "sunday"):
return "holy_family" # sunday after christmas
if (month, day) == ("december", 30) and christmas_day_weekday == "sunday":
return "holy_family" # if christmas is a sunday then december 30

if day in HOLIDAYS["dates"][month].keys():
return HOLIDAYS["dates"][month][day]

Expand Down
7 changes: 5 additions & 2 deletions poems/poem.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ def email_html(self):
return f'''<!DOCTYPE html>
<html lang="en">
<section style="text-align: left; max-width: 960px; font-family: Baskerville; font-size: 18px;">
<section style="padding-bottom: 32px;">
<section id="header" style="padding-bottom: 32px;">
{self.email_header}
</section>
<section style="padding-bottom: 32px;">
<section id="body" style="padding-bottom: 32px;">
{self.html_body}
</section>
<section id="footer" style="padding-bottom: 32px;">
{self.spacetime}
</section>
<section>
<a href="https://thomaswmorris.com/poems">daily poems archive</a>
</section>
Expand Down
1 change: 1 addition & 0 deletions poems/weights.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
"saint_stephen": 365.25,
"saint_john_the_apostle": 365.25,
"holy_innocents": 365.25,
"holy_family": 365.25,
"saint_thomas_becket": 365.25,
"saint_egwin": 365.25,
"new_years_eve": 365.25
Expand Down
9 changes: 4 additions & 5 deletions scripts/compile-weights.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import datetime, json, numpy, os, pandas, sys, yaml
base, this_file = os.path.split(__file__)

sys.path.append(f"/users/tom/repos/poemsfromtom/poems")
import utils
from poems import utils

context_categories = [key for key in utils.get_context_dict(0).keys() if not key == "timestamp"]
context_categories = [key for key in utils.Context(0).keys() if not key == "timestamp"]
sample_times = numpy.arange(datetime.datetime(2000, 1, 1, 12).timestamp(), datetime.datetime(2100, 1, 1, 12).timestamp(), 86400)

sampled_context_values = numpy.array([list(utils.get_context_dict(t).values()) for t in sample_times])
sampled_context = pandas.DataFrame(sampled_context_values, columns=utils.get_context_dict().keys())
sampled_context_values = numpy.array([list(utils.Context(t).values()) for t in sample_times])
sampled_context = pandas.DataFrame(sampled_context_values, columns=utils.Context.now().keys())

CONTEXT_MULTIPLIERS = {}
for category in ['weekday', 'month', 'day', 'season', 'liturgy', 'holiday', 'month_epoch']:
Expand Down
3 changes: 1 addition & 2 deletions scripts/send-poem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
parser.add_argument("--github_repo_name", type=str, help="Which GH repository to load", default="")
parser.add_argument("--github_token", type=str, help="GH token", default="")
parser.add_argument("--kind", type=str, help="What tag to write to the history with", default="")
parser.add_argument("--write_to_repo", type=bool, help="Should we update the repo", default=False)
parser.add_argument('--write_to_repo', action=argparse.BooleanOptionalAction)
args = parser.parse_args()

test = (args.kind == "test")
Expand Down Expand Up @@ -83,7 +83,6 @@
warnings.warn(f"Could not find poem for entry {entry}")

if args.write_to_repo:

utils.write_to_repo(repo,
items={
"data/poems/history-daily.csv": history.to_csv(),
Expand Down

0 comments on commit 64e6f57

Please sign in to comment.