|
1 | | -# Script to automatically generate dart files mapping the OET-RV sections from the OET json files |
| 1 | +# Script to automatically generate a dart file mapping the OET-RV sections from the OET json files |
2 | 2 | # Requirements: Python 3 and the standard library |
3 | 3 |
|
4 | 4 | # The resulting oet_rv_section_headings.dart file is formatted like so: |
|
14 | 14 | # ], |
15 | 15 | # }; |
16 | 16 |
|
17 | | -# The resulting oet_rv_section_start_end.dart file is formatted like so: |
18 | | -# |
19 | | -# Map<String, List<Map<String, dynamic>>> sectionStartEndMappingForOET = { |
20 | | -# 'JHN': { |
21 | | -# '1:1': { |
22 | | -# 'section': 'The coming of the true light', |
23 | | -# 'start' : { |
24 | | -# 'chapter': 1, |
25 | | -# 'verse': 1, |
26 | | -# }, |
27 | | -# 'end': { |
28 | | -# 'chapter': 1, |
29 | | -# 'verse': 2, |
30 | | -# } |
31 | | -# } |
32 | | -# } |
33 | | -# } |
34 | | - |
35 | | - |
36 | 17 | import os |
37 | 18 | import re |
38 | 19 | import json |
39 | 20 |
|
40 | 21 | RV_local_path = "./OET-RV/" |
41 | 22 | oet_rv_section_headings_file = "../../lib/common/oet_rv_section_headings.dart" |
42 | | -oet_rv_section_start_end_file = "../../lib/common/oet_rv_section_start_end.dart" |
43 | 23 |
|
44 | 24 | section_headings_dart_file_template = """ |
45 | 25 | // GENERATED FILE. DO NOT EDIT DIRECTLY |
|
48 | 28 | Map<String, List<List<String>>> sectionHeadingsMappingForOET = {}; |
49 | 29 | """ |
50 | 30 |
|
51 | | -section_start_end_dart_file_template = """ |
52 | | -// GENERATED FILE. DO NOT EDIT DIRECTLY |
53 | | -// This file can be regenerated by running the update_OET_sections.py file |
54 | | -
|
55 | | -Map<String, List<Map<String, dynamic>>> sectionStartEndMappingForOET = {}; |
56 | | -""" |
57 | | - |
58 | 31 |
|
59 | 32 | def generate_headings_mappings_file(): |
60 | 33 | file_list = os.listdir(RV_local_path) |
@@ -119,53 +92,6 @@ def generate_headings_mappings_file(): |
119 | 92 | with open(oet_rv_section_headings_file, "w") as file: |
120 | 93 | file.write(contents) |
121 | 94 |
|
122 | | - return sections_mapping |
123 | | - |
124 | | - |
125 | | -def generate_start_end_mappings_file(sections_mapping): |
126 | | - start_end_sections = {} |
127 | | - for book in sections_mapping: |
128 | | - book_sections = sections_mapping[book] |
129 | | - list_length = len(book_sections) |
130 | | - |
131 | | - inner = [] |
132 | | - for index in range(0, list_length): |
133 | | - |
134 | | - # Section start |
135 | | - start = book_sections[index][0] |
136 | | - start_section_ref = section_ref_from_section(start) |
137 | | - start_chapter_ref, start_verse_ref = split_section_ref(start_section_ref) |
138 | | - |
139 | | - # Section end |
140 | | - if index+1 < list_length: |
141 | | - # A section can be spread over two chapters |
142 | | - next_section = book_sections[index+1][0] |
143 | | - end = next_section |
144 | | - else: |
145 | | - end = start |
146 | | - |
147 | | - end_section_ref = section_ref_from_section(end) |
148 | | - end_chapter_ref, end_verse_ref = split_section_ref(end_section_ref) |
149 | | - |
150 | | - inner.append({ |
151 | | - 'section': section_heading_from_section(start), |
152 | | - 'start': { |
153 | | - 'chapter': int(start_chapter_ref), |
154 | | - 'verse': int(start_verse_ref), |
155 | | - }, |
156 | | - 'end': { |
157 | | - 'chapter': int(end_chapter_ref), |
158 | | - 'verse': int(end_verse_ref), |
159 | | - } |
160 | | - }) |
161 | | - |
162 | | - start_end_sections[book] = inner |
163 | | - |
164 | | - contents = section_start_end_dart_file_template.format(str(start_end_sections)) |
165 | | - |
166 | | - with open(oet_rv_section_start_end_file, "w") as file: |
167 | | - file.write(contents) |
168 | | - |
169 | 95 |
|
170 | 96 | def read_json_file(path): |
171 | 97 | with open(path, "r") as json_file: |
@@ -196,8 +122,7 @@ def split_section_ref(ref): |
196 | 122 |
|
197 | 123 |
|
198 | 124 | if __name__ == "__main__": |
199 | | - print("Generating files...") |
200 | | - sections_mapping = generate_headings_mappings_file() |
201 | | - generate_start_end_mappings_file(sections_mapping) |
| 125 | + print("Generating file...") |
| 126 | + generate_headings_mappings_file() |
202 | 127 | print("Generating complete.") |
203 | 128 |
|
0 commit comments