aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Moch2018-02-28 06:53:18 -0500
committerDaniel Moch2018-02-28 06:53:18 -0500
commitc74a05c35364e882f0cc8b86d4d527c56363bb09 (patch)
treebcd59f40323f2e4a7603c09a2e3237c243453b02
parent36058b4e137587bbd33dee58f533128851e981b9 (diff)
downloadcbr-schedule-c74a05c35364e882f0cc8b86d4d527c56363bb09.tar.gz
Add CSV export
-rw-r--r--Makefile3
-rw-r--r--schedule.py24
2 files changed, 26 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 139e46b..2c5a3a1 100644
--- 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
index 6b92c4e..285bb6d 100644
--- a/schedule.py
+++ b/schedule.py
@@ -26,6 +26,10 @@ import json
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 @@ class Schedule:
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)