-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_plan4.py
224 lines (188 loc) · 6.97 KB
/
create_plan4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import calendar
import csv
import datetime
import re
import string
from dataclasses import dataclass
from prettytable import PrettyTable
def get_chapter_counts() -> dict[str, str]:
chapter_counts: dict[str, str] = {}
with open("bible_book_info.csv", "r", encoding="utf-8") as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
chapter_counts[row["book"]] = row["chapters"]
return chapter_counts
class BookGroup:
# Set by constructor
group_name: str
book_list: list[str]
reading_index: int
readings: list[str]
def __init__(self, group_name: str, book_list: list[str], reading_index: int = 0):
self.group_name = group_name
self.book_list = book_list
self.reading_index = reading_index
def set_readings(self, chapter_counts: dict[str, str]):
self.readings = []
for book in self.book_list:
for chapter in range(1, int(chapter_counts[book]) + 1):
self.readings.append(f"{book} {chapter}")
def increment_reading_index(self):
if self.reading_index < len(self.readings) - 1:
self.reading_index += 1
else:
self.reading_index = 0
@dataclass
class MonthWithStartDay:
month_name: str | None
day: int
@dataclass
class ReadingsInfo:
page_title: str
column_names: list[str]
plan_readings: list[list[str]]
def get_overall_readings_info(
start_date: datetime.date,
end_date: datetime.date,
book_groups: list[BookGroup],
) -> ReadingsInfo:
page_title: str = f"Horner Classic Bible Reading Plan for: {start_date} to {end_date}"
column_names: list[str] = ["Date"] + [book_group.group_name for book_group in book_groups]
chapter_counts: dict[str, str] = get_chapter_counts()
for book_group in book_groups:
book_group.set_readings(chapter_counts)
# group_names_with_num_readings = {book_group.group_name : len(book_group.readings) for book_group in book_groups}
# print(f"Groups, each with its number of distinct readings: {group_names_with_num_readings}\n")
plan_readings: list[list[str]] = []
number_of_days_in_plan = (end_date - start_date).days + 1
date: datetime.date = start_date
for day in range(number_of_days_in_plan):
days_readings: list[str] = [str(date)]
for book_group in book_groups:
days_readings.append(book_group.readings[book_group.reading_index])
book_group.increment_reading_index()
date += datetime.timedelta(days=1)
plan_readings.append(days_readings)
overall_readings_info = ReadingsInfo(page_title, column_names, plan_readings)
return overall_readings_info
def get_one_big_table(overall_readings_info: ReadingsInfo):
table: PrettyTable = PrettyTable(overall_readings_info.column_names)
for reading in overall_readings_info.plan_readings:
table.add_row(reading)
return table
def write_one_big_table(page_title: str, table: PrettyTable):
headings_and_tables = f"<h3>{page_title}</h3>"
html_string = table.get_html_string()
headings_and_tables += html_string
with open("template4.html", "r", encoding="utf-8") as template_file:
template_string = template_file.read()
text_template = string.Template(template_string)
readings = text_template.substitute(page_title=page_title,
headings_and_tables=headings_and_tables)
readings = readings.replace('<table>', '<table role="presentation">')
with open("one-big-table.html", "w", encoding="utf-8") as html_file:
html_file.writelines(readings)
def main():
book_groups: list[BookGroup] = [
BookGroup("Gospels", ["Matthew", "Mark", "Luke", "John"]),
BookGroup("Pentateuch", ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy"]),
BookGroup(
"Epistles1",
[
"Romans",
"1 Corinthians",
"2 Corinthians",
"Galatians",
"Ephesians",
"Philippians",
"Colossians",
"Hebrews",
],
),
BookGroup(
"Epistles2",
[
"1 Thessalonians",
"2 Thessalonians",
"1 Timothy",
"2 Timothy",
"Titus",
"Philemon",
"James",
"1 Peter",
"2 Peter",
"1 John",
"2 John",
"3 John",
"Jude",
"Revelation",
],
),
BookGroup("Wisdom", ["Job", "Ecclesiastes", "Song of Songs"]),
BookGroup("Psalms", ["Psalms"]),
BookGroup("Proverbs", ["Proverbs"]),
BookGroup(
"History",
[
"Joshua",
"Judges",
"Ruth",
"1 Samuel",
"2 Samuel",
"1 Kings",
"2 Kings",
"1 Chronicles",
"2 Chronicles",
"Ezra",
"Nehemiah",
"Esther",
],
),
BookGroup(
"Prophets",
[
"Isaiah",
"Jeremiah",
"Lamentations",
"Ezekiel",
"Daniel",
"Hosea",
"Joel",
"Amos",
"Obadiah",
"Jonah",
"Micah",
"Nahum",
"Habakkuk",
"Zephaniah",
"Haggai",
"Zechariah",
"Malachi",
],
),
BookGroup("Acts", ["Acts"]),
]
start_date = datetime.date(2023, 1, 1)
end_date = datetime.date(2023, 12, 31)
date_range: str = f"{start_date.strftime('%Y%m%d')}-{end_date.strftime('%Y%m%d')}"
overall_readings_info: ReadingsInfo = get_overall_readings_info(start_date, end_date, book_groups)
table = get_one_big_table(overall_readings_info)
write_one_big_table(overall_readings_info.page_title, table)
# TODO: Get and write month tables
months_of_readings: list[ReadingsInfo] = []
previous_year_and_month: str | None = None
current_year_and_month: str | None = None
day: int | None = None
months_with_start_days: list[MonthWithStartDay] = []
for day, reading in enumerate(overall_readings_info.plan_readings):
current_year_and_month = reading[0][0:7]
if current_year_and_month != previous_year_and_month:
months_with_start_days += [MonthWithStartDay(current_year_and_month, day)]
previous_year_and_month = current_year_and_month
if day:
months_with_start_days += [MonthWithStartDay(current_year_and_month, day + 1)]
for index, month_with_start_day in enumerate(months_with_start_days[:-1]):
end_day = months_with_start_days[index+1].day
print(month_with_start_day.month_name, month_with_start_day.day, end_day)
if __name__ == "__main__":
main()