cbr-schedule

An unofficial Bible-reading-plan generator
git clone git://git.danielmoch.com/cbr-schedule.git
Log | Files | Refs | README | LICENSE

commit 5853624dfa7af48bc658ee84b02631408b3d8067
parent aba60175b6e294f6ee18cd9be14189d6c62e7b00
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat,  3 Mar 2018 13:26:08 -0500

Add LaTeX output format.

Diffstat:
MMakefile | 3+++
MREADME.md | 12+++++++-----
Mschedule.py | 35+++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile @@ -32,6 +32,9 @@ csv: $(SECTIONS) json: $(SECTIONS) ./generate_schedule output.json +latex: $(SECTIONS) + ./generate_schedule output.tex + clean: rm output.* rm sections/*.json diff --git a/README.md b/README.md @@ -9,12 +9,9 @@ Currently available export formats are: 1. JSON (machine-readable so you can do what you want with it) 2. Formatted text file - -Other export formats on the roadmap: - -1. LaTeX (for generating PDF files, or other similar formats, assuming +3. Comma-separated values (CSV) (for importing into spreadsheets) +4. LaTeX (for generating PDF files, or other similar formats, assuming you have access to the LaTeX suite) -2. CSV (for importing into spreadsheets) ## Requirements @@ -25,6 +22,11 @@ Other export formats on the roadmap: 1. `make text` builds a formatted text file (also built with simply `make`) 2. `make json` builds a JSON file +3. `make csv` builds a CSV file +4. `make latex` build a LaTeX file. From there building a PDF for DVI + file is just a short command away. I would add additional targets to + the Makefile for each of these, but I was getting weird artifacts in + the output files when I build this way. ## License diff --git a/schedule.py b/schedule.py @@ -26,6 +26,7 @@ class Schedule: data = [] filename = None + _year = "2018" _column_section_mapping = { 'Old Testament': ('Old Testament', 'Psalms',), 'New Testament': ('New Testament',) @@ -71,6 +72,38 @@ def _csv_export(self, outfile): reading['reading'] + '"') outfile.write('\n') + def _latex_export(self, outfile): + outfile.write('\\documentclass[a4paper]{article}\n\n') + outfile.write('\\pagenumbering{gobble}\n\n') + outfile.write('\\usepackage{longtable}\n\n') + outfile.write('\\usepackage{tabu}\n\n') + outfile.write('\\usepackage[margin=0.5in]{geometry}\n\n') + outfile.write('\\title{Bible Reading Plan}\n\n') + outfile.write('\\author{' + self._year + '}\n\n') + outfile.write('\\date{}\n\n') + outfile.write('\\begin{document}\n\n') + outfile.write('\\maketitle\n\n') + outfile.write('\\begin{longtabu} to \\linewidth{ l') + for col in range(len(self._column_section_mapping) - 1): + outfile.write(' X[2,l]') + outfile.write(' X[3,l] }\n\n') + outfile.write('\\rowfont\\bfseries Date') + for column in self._column_section_mapping: + outfile.write(' & ' + column) + outfile.write(' \\\\ \\hline\\endhead\n\n') + for entry in self.data: + outfile.write(entry['day_of_week'] + ', ' + entry['month'] \ + + ' ' + str(entry['day'])) + for column in self._column_section_mapping.keys(): + for reading in entry['readings']: + if reading['section'] in \ + self._column_section_mapping[column]: + outfile.write(' & ' + reading['book'] + ' ' + \ + reading['reading']) + outfile.write(' \\\\ \\hline\n') + outfile.write('\n\\end{longtabu}\n\n') + outfile.write('\\end{document}\n\n') + def export(self): self._assert_initialized() file_extension = self.filename.split('.')[-1] @@ -82,5 +115,7 @@ def export(self): self._txt_export(outfile) elif file_extension == 'csv': self._csv_export(outfile) + elif file_extension == 'tex': + self._latex_export(outfile) else: raise RuntimeError('Schedule: cannot determine export type')