cbr-schedule

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

commit c74a05c35364e882f0cc8b86d4d527c56363bb09
parent 36058b4e137587bbd33dee58f533128851e981b9
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Wed, 28 Feb 2018 06:53:18 -0500

Add CSV export

Diffstat:
MMakefile | 3+++
Mschedule.py | 24+++++++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -26,6 +26,9 @@ SECTIONS=sections/new_testament.json sections/old_testament.json sections/psalms text: $(SECTIONS) ./generate_schedule output.txt +csv: $(SECTIONS) + ./generate_schedule output.csv + json: $(SECTIONS) ./generate_schedule output.json diff --git a/schedule.py b/schedule.py @@ -26,6 +26,10 @@ class Schedule: data = [] filename = None + _column_section_mapping = { + 'Old Testament': ('Old Testament', 'Psalms',), + 'New Testament': ('New Testament',) + } def _assert_initialized(self): if self.filename is None: @@ -51,10 +55,28 @@ def _txt_export(self, outfile): outfile.write('\tNo reading\n') outfile.write('\n') + def _csv_export(self, outfile): + outfile.write('"Date"') + for column in self._column_section_mapping: + outfile.write(',"' + column + '"') + outfile.write('\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(",") + outfile.write('\n') + def export(self): self._assert_initialized() file_extension = self.filename.split('.')[-1] - + with open(self.filename, 'w') as outfile: if file_extension == 'json': self._json_export(outfile)