aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Moch2018-03-03 13:26:08 -0500
committerDaniel Moch2018-03-03 13:26:08 -0500
commit5853624dfa7af48bc658ee84b02631408b3d8067 (patch)
tree280e6fbabfa88d5acf13d55290b3f1da11469232
parentaba60175b6e294f6ee18cd9be14189d6c62e7b00 (diff)
downloadcbr-schedule-5853624dfa7af48bc658ee84b02631408b3d8067.tar.gz
Add LaTeX output format.
-rw-r--r--Makefile3
-rw-r--r--README.md12
-rw-r--r--schedule.py35
3 files changed, 45 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 2c5a3a1..b20cb0a 100644
--- 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
index 7917a64..a40da70 100644
--- 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
index 0443ad3..330a2d1 100644
--- a/schedule.py
+++ b/schedule.py
@@ -26,6 +26,7 @@ import json
class Schedule:
data = []
filename = None
+ _year = "2018"
_column_section_mapping = {
'Old Testament': ('Old Testament', 'Psalms',),
'New Testament': ('New Testament',)
@@ -71,6 +72,38 @@ class Schedule:
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 @@ class Schedule:
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')