GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — scriptures/scripts/make-flat.py at main · allancoding/scriptures

Expand file tree

/

make-flat.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
78 lines (59 loc) · 2.32 KB
/

make-flat.py

Copy path

File metadata and controls

78 lines (59 loc) · 2.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import json, sys
from pathlib import Path
script_dir = Path(__file__).resolve().parent
def make_flat(input_path: Path) -> None:
output_path = script_dir.parent / 'flat' / input_path.name.replace('.json', '-flat.json')
with open(input_path, 'r', encoding='utf-8') as f:
data = f.read()
data = json.loads(data)
verses = []
headings = []
def verse_reference(book_title: str, chapter_number: int, verse_number: int) -> str:
return f'{book_title} {chapter_number}:{verse_number}'
# Everything but D&C
if 'books' in data:
for b in data['books']:
book_title = b.get('title', b.get('book', ''))
if 'heading' in b:
headings.append({
'text': b['heading'],
'reference': book_title,
})
for c in b['chapters']:
chapter = c.get('chapter', c)
chapter_number = chapter.get('number')
if 'heading' in c:
headings.append({
'text': c['heading'],
'reference': book_title,
})
for v in chapter.get('verses', []):
verses.append({
'text': v['text'],
'reference': verse_reference(book_title, chapter_number, v['verseNumber']),
})
# D&C
if 'sections' in data:
for s in data['sections']:
book_title = data.get('title', data.get('book', 'Doctrine and Covenants'))
for v in s['verses']:
verses.append({
'text': v['text'],
'reference': verse_reference(book_title, s.get('sectionNumber', s.get('number')), v['verseNumber']),
})
data = {
'headings': headings,
'verses': verses
}
if len(headings) == 0:
del data['headings']
with open(output_path, 'w', encoding='utf-8') as f:
json.dump(data, f, sort_keys=True, indent=4, ensure_ascii=False)
input_dir = script_dir.parent / 'complete' / 'scriptures'
if len(sys.argv) == 1:
input_paths = sorted(input_dir.glob('*.json'))
else:
input_paths = [input_dir / Path(arg).name for arg in sys.argv[1:]]
for input_path in input_paths:
make_flat(input_path)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.