commit 875b62f9bc36a73b76bfc9f3f756b353a09b4747 parent 848900be544ae5aa09f22fd35ac4f39520932fd2 Author: Daniel Moch <daniel@danielmoch.com> Date: Sat, 24 Feb 2018 10:27:49 -0500 Handle edge case in generate_readings The initial commit failed to handle an edge case where a chapter is not read in a single day (currently the only case of this is Psalm 119). This version of generate_readings accounts for this. Diffstat:
M | generate_readings | | | 30 | +++++++++++++++++++++++------- |
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/generate_readings b/generate_readings @@ -33,16 +33,32 @@ def generate_readings(infilename): readings = [] idx = 0 for book, info in section: + subchapter_readings = () + if len(info) > 1: + subchapter_readings = info[1] chapters = info[0] chapter = 1 while chapter <= chapters: - reading = {} - reading['index'] = idx - reading['book'] = book - reading['chapter'] = chapter - readings.append(reading) - idx += 1 - chapter += 1 + chapter_str = str(chapter) + if chapter_str in subchapter_readings: + for subchapter_reading in \ + subchapter_readings[chapter_str]: + reading = {} + reading['index'] = idx + reading['book'] = book + reading['reading'] = chapter_str + ':' + \ + subchapter_reading + readings.append(reading) + idx += 1 + chapter += 1 + else: + reading = {} + reading['index'] = idx + reading['book'] = book + reading['reading'] = chapter_str + readings.append(reading) + idx += 1 + chapter += 1 with open(filename, 'w') as outfile: json.dump(readings, outfile)