Skip to content

Commit

Permalink
Support for date overrides
Browse files Browse the repository at this point in the history
Use date overrides for multi-day events. Also some bug fixes in date
display (now shows day of week by default), argument parsing and help
messages, and the intermediate hymn flag.
  • Loading branch information
snay2 committed Jun 14, 2014
1 parent 7be7d1c commit 1d6f24b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These Python scripts generate a LaTeX document for a weekly LDS ward bulletin. T

Invoke the generator like this:

python generate.py bulletin.json
python generate.py bulletin.json [--template template.tex] [--output bulletin.tex]

Make sure your `bulletin.json`, `lessons.json`, `primary.json`, `organizations.json`, and `calendar.json` files are up to date.

Expand Down
9 changes: 6 additions & 3 deletions bulletin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def get_parameters(self):
def parse_date(self, date_to_parse):
return datetime.strptime(date_to_parse, "%d %B %Y")

def pretty_date(self, orig_date):
return self.parse_date(orig_date).strftime("%A %d %B")
def pretty_date(self, item):
item['date'] = self.parse_date(item['date']).strftime("%A %d %B")
return item

def is_this_week(self, item):
date_to_test = self.parse_date(item['date'])
Expand All @@ -48,6 +49,8 @@ def filter_calendar(self, events):
calendar = {}
calendar['this_week'] = filter(self.is_this_week, events)
calendar['next_week'] = filter(self.is_next_week, events)
map(self.pretty_date, calendar['this_week'])
map(self.pretty_date, calendar['next_week'])
return calendar

def filter_orgs(self, orgs):
Expand All @@ -62,6 +65,6 @@ def filter_lessons(self, lessons, type):
def filter_primary(self, assignments):
primary = {}
primary['this_week'] = filter(self.is_this_week, assignments)[0]
primary['next_week'] = filter(self.is_this_week, assignments)[0]
primary['next_week'] = filter(self.is_next_week, assignments)[0]
return primary

7 changes: 4 additions & 3 deletions calendar.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"events": [
{
"date": "15 June 2014",
"date": "17 June 2014",
"date-override": "17--22 June"
"time": "",
"place": "",
"title": "Church cleaning",
"descr": "The following families are responsible for this week: "
"title": "Utah County Single Adult Conference",
"descr": "This is an example of using a date override for a multi-day event"
},
{
"date": "20 June 2014",
Expand Down
2 changes: 1 addition & 1 deletion generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate(input_json, template_tex, output_tex):

def main():
parser = argparse.ArgumentParser(description='Generate a LaTeX ward bulletin from the given configs')
parser.add_argument('--template', default='template.tex', help='LaTeX template file with Cheetah placeholders')
parser.add_argument('--template', default='template.tex', help='LaTeX template file with Cheetah placeholders (default template.tex)')
parser.add_argument('--output', default='bulletin.tex', help='output file destination (default bulletin.tex)')
parser.add_argument('input_file', help='JSON config file')
args = vars(parser.parse_args())
Expand Down
10 changes: 10 additions & 0 deletions template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ \section{Sacrament Meeting}
#end if
\\
#end if
#if $has_rest_hymn
\textbf{Intermediate Hymn} & $rest_hymn \\
#end if
#for $speaker in $speakers_after
\textbf{$speaker.type} & $speaker.name \\
#end for
Expand All @@ -185,7 +187,11 @@ \section{Calendar}
\multicolumn{2}{c}{\textbf{This week}} \\
\hline
#for $event in $calendar['this_week']
#if 'date_override' in $event
$event['date_override']
#else
$event['date']
#end if
#if $event['time']
\newline @ $event['time']
#end if
Expand All @@ -203,7 +209,11 @@ \section{Calendar}
\multicolumn{2}{c}{\textbf{Next week}} \\
\hline
#for $event in $calendar['next_week']
#if 'date_override' in $event
$event['date_override']
#else
$event['date']
#end if
#if $event['time']
\newline @ $event['time']
#end if
Expand Down

0 comments on commit 1d6f24b

Please sign in to comment.