scripturelookup 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/.gitignore +1 -0
  2. scripturelookup-0.0.2/PKG-INFO +154 -0
  3. scripturelookup-0.0.2/README.md +117 -0
  4. scripturelookup-0.0.2/requirements.txt +2 -0
  5. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup/command_line.py +3 -1
  6. scripturelookup-0.0.2/src/scripturelookup/data.py +117 -0
  7. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup/lookup.py +15 -1
  8. scripturelookup-0.0.2/src/scripturelookup.egg-info/PKG-INFO +154 -0
  9. scripturelookup-0.0.1/PKG-INFO +0 -40
  10. scripturelookup-0.0.1/README.md +0 -3
  11. scripturelookup-0.0.1/requirements.txt +0 -3
  12. scripturelookup-0.0.1/src/scripturelookup/data.py +0 -58
  13. scripturelookup-0.0.1/src/scripturelookup.egg-info/PKG-INFO +0 -40
  14. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/.github/workflows/publish.yml +0 -0
  15. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/LICENSE +0 -0
  16. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/pyproject.toml +0 -0
  17. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/setup.cfg +0 -0
  18. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/LICENSE +0 -0
  19. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/README.md +0 -0
  20. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/arabify.py +0 -0
  21. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/arabify_test.py +0 -0
  22. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/geezify.py +0 -0
  23. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/geezify_test.py +0 -0
  24. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/geezify-python-main/test_data.py +0 -0
  25. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup/__init__.py +0 -0
  26. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup/data/metadata-languages.min.json +0 -0
  27. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup/data/metadata-scriptures.min.json +0 -0
  28. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup/numbers.py +0 -0
  29. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup.egg-info/SOURCES.txt +0 -0
  30. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup.egg-info/dependency_links.txt +0 -0
  31. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup.egg-info/entry_points.txt +0 -0
  32. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup.egg-info/requires.txt +0 -0
  33. {scripturelookup-0.0.1 → scripturelookup-0.0.2}/src/scripturelookup.egg-info/top_level.txt +0 -0
@@ -7,3 +7,4 @@ __pycache__/
7
7
  Icon?
8
8
  *~
9
9
 
10
+ localtesting.py
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.1
2
+ Name: scripturelookup
3
+ Version: 0.0.2
4
+ Summary: Python and command-line utility for converting scripture references between formats.
5
+ Author-email: Samuel Bradshaw <samuel.h.bradshaw@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Samuel Bradshaw
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Repository, https://github.com/samuelbradshaw/python-scripture-lookup
28
+ Project-URL: Issues, https://github.com/samuelbradshaw/python-scripture-lookup/issues
29
+ Project-URL: Changelog, https://github.com/samuelbradshaw/python-scripture-lookup/releases
30
+ Keywords: python,command,scripture,bible,book of mormon,reference
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3
33
+ Requires-Python: >=3.8
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: requests
37
+
38
+ # Scripture Lookup
39
+
40
+ Scripture Lookup is a Python library and command-line tool for looking up scripture verses or chapters. It can also convert scripture references between formats and languages. The tool is built around data from [Python Scripture Scraper](https://github.com/samuelbradshaw/python-scripture-scraper).
41
+
42
+
43
+ ## Installation
44
+
45
+ The Python package and command-line tool can be installed from [PyPI](https://pypi.org/project/scripturelookup/) via pip:
46
+ ```
47
+ pip install scripturelookup
48
+ ```
49
+
50
+
51
+ ## Command-line usage
52
+
53
+ Pattern:
54
+ ```
55
+ scripturelookup [command] [input] [options]
56
+ ```
57
+
58
+ Examples:
59
+ ```
60
+ % scripturelookup get_content "john 3:16" --lang "en"
61
+ 16 ¶ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
62
+
63
+ % scripturelookup get_label "니파이전서 3:7" --lang "fr" --abbreviated
64
+ 1 Né 3:7
65
+
66
+ % scripturelookup get_church_url "helaman 5:12"
67
+ https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
68
+
69
+ % scripturelookup get_label "/scriptures/nt/1-jn/3.2-3" --lang "cmn-Hant"
70
+ 約翰一書3:2-3
71
+
72
+ % scripturelookup get_church_url "/scriptures/ot" --lang "es"
73
+ https://www.churchofjesuschrist.org/study/scriptures/ot?lang=spa
74
+ ```
75
+
76
+
77
+ ## Python usage
78
+
79
+ Examples:
80
+ ```
81
+ from scripturelookup import lookup
82
+
83
+ lookup.get_content('john 3:16', lang = 'en')
84
+ # 16 ¶ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
85
+
86
+ lookup.get_label('니파이전서 3:7', lang = 'fr', abbreviated = True)
87
+ # 1 Né 3:7
88
+
89
+ lookup.get_church_url('helaman 5:12')
90
+ # https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
91
+
92
+ lookup.get_label('/scriptures/nt/1-jn/3.2-3', lang = 'cmn-Hant')
93
+ # 約翰一書3:2-3
94
+
95
+ lookup.get_church_url('/scriptures/ot', lang = 'es')
96
+ # https://www.churchofjesuschrist.org/study/scriptures/ot?lang=spa
97
+ ```
98
+
99
+
100
+ ## Commands, inputs, and options
101
+
102
+ ### Commands
103
+
104
+ - **get_content** – Get chapter or verse content.
105
+ - **get_label** – Get a scripture reference label (i.e. "John 3:16").
106
+ - **get_church_uri** – Get a Gospel Library URI (i.e. "/scriptures/bofm/hel/5.12").
107
+ - **get_church_url** – Get a Gospel Library URL.
108
+ - **get_church_link** – Get an HTML link to Gospel Library.
109
+
110
+ ### Inputs
111
+
112
+ Any of the following input types are supported. You can also provide several inputs at once as a list (separated by semicolons or line-breaks).
113
+
114
+ - Chapter or verse references, in any supported language. Examples:
115
+ - John 3:16
116
+ - Enos 1:13, 15–18
117
+ - Psalm 23
118
+ - Gen. 1:3 (3–4)
119
+ - D&C 20:23; 76:41
120
+ - Scripture publication or book names. Examples:
121
+ - Old Testament
122
+ - Book of Mormon
123
+ - 1 Corinthians
124
+ - Psalms
125
+ - Gospel Library URIs (starting with `/scriptures`). Examples:
126
+ - /scriptures/ot/gen
127
+ - /scriptures/nt/matt/1
128
+ - /scriptures/nt/john/3.16
129
+ - /scriptures/bofm/enos/1.13,15-18
130
+ - /scriptures/pgp
131
+ - Gospel Library URLs (old or new). Examples:
132
+ - https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
133
+ - https://www.churchofjesuschrist.org/study/scriptures/ot?lang=eng
134
+ - http://lds.org/scriptures/bofm/1-ne/3.7?lang=eng
135
+
136
+ ### Options
137
+
138
+ Several options are available. Some are only applicable to certain commands.
139
+
140
+ - **lang** (optional) – Output language. BCP 47 language codes and Gospel Library language codes are supported. Default: 'en'.
141
+ - **separator** (optional) – String separator between outputs when a list of references is being requested. Default: '\n'.
142
+ - **source** (optional) – Content source. Default: 'python-scripture-scraper'. Supported values: 'python-scripture-scraper' or 'ChurchofJesusChrist.org'.
143
+ - **link_class** (optional) – String for the “class” attribute on links. Default: None.
144
+ - **link_target** (optional) – String for the “target” attribute on links. Default: None.
145
+ - **use_query_parameters** (optional) – Whether query parameters should be used on URIs. Default: False.
146
+ - **skip_lang** (optional) – Whether “lang” query parameters should be skipped on URLs. Default: False.
147
+ - **skip_fragment** (optional) – Whether fragments should be skipped on URLs. Default: False.
148
+ - **skip_book_name** (optional) – Whether book names should be skipped on labels. Default: False.
149
+ - **abbreviated** (optional) – Whether book abbrevions should be used on labels. Default: False.
150
+
151
+
152
+ ## Acknowledgements
153
+ [Python Scripture Scraper](https://github.com/samuelbradshaw/python-scripture-scraper) – tool for scraping scripture content and metadata from ChurchofJesusChrist.org.
154
+ [geezify-python](https://github.com/logicalperson0/geezify-python) – tool for converting numbers to and from Geez numerals.
@@ -0,0 +1,117 @@
1
+ # Scripture Lookup
2
+
3
+ Scripture Lookup is a Python library and command-line tool for looking up scripture verses or chapters. It can also convert scripture references between formats and languages. The tool is built around data from [Python Scripture Scraper](https://github.com/samuelbradshaw/python-scripture-scraper).
4
+
5
+
6
+ ## Installation
7
+
8
+ The Python package and command-line tool can be installed from [PyPI](https://pypi.org/project/scripturelookup/) via pip:
9
+ ```
10
+ pip install scripturelookup
11
+ ```
12
+
13
+
14
+ ## Command-line usage
15
+
16
+ Pattern:
17
+ ```
18
+ scripturelookup [command] [input] [options]
19
+ ```
20
+
21
+ Examples:
22
+ ```
23
+ % scripturelookup get_content "john 3:16" --lang "en"
24
+ 16 ¶ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
25
+
26
+ % scripturelookup get_label "니파이전서 3:7" --lang "fr" --abbreviated
27
+ 1 Né 3:7
28
+
29
+ % scripturelookup get_church_url "helaman 5:12"
30
+ https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
31
+
32
+ % scripturelookup get_label "/scriptures/nt/1-jn/3.2-3" --lang "cmn-Hant"
33
+ 約翰一書3:2-3
34
+
35
+ % scripturelookup get_church_url "/scriptures/ot" --lang "es"
36
+ https://www.churchofjesuschrist.org/study/scriptures/ot?lang=spa
37
+ ```
38
+
39
+
40
+ ## Python usage
41
+
42
+ Examples:
43
+ ```
44
+ from scripturelookup import lookup
45
+
46
+ lookup.get_content('john 3:16', lang = 'en')
47
+ # 16 ¶ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
48
+
49
+ lookup.get_label('니파이전서 3:7', lang = 'fr', abbreviated = True)
50
+ # 1 Né 3:7
51
+
52
+ lookup.get_church_url('helaman 5:12')
53
+ # https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
54
+
55
+ lookup.get_label('/scriptures/nt/1-jn/3.2-3', lang = 'cmn-Hant')
56
+ # 約翰一書3:2-3
57
+
58
+ lookup.get_church_url('/scriptures/ot', lang = 'es')
59
+ # https://www.churchofjesuschrist.org/study/scriptures/ot?lang=spa
60
+ ```
61
+
62
+
63
+ ## Commands, inputs, and options
64
+
65
+ ### Commands
66
+
67
+ - **get_content** – Get chapter or verse content.
68
+ - **get_label** – Get a scripture reference label (i.e. "John 3:16").
69
+ - **get_church_uri** – Get a Gospel Library URI (i.e. "/scriptures/bofm/hel/5.12").
70
+ - **get_church_url** – Get a Gospel Library URL.
71
+ - **get_church_link** – Get an HTML link to Gospel Library.
72
+
73
+ ### Inputs
74
+
75
+ Any of the following input types are supported. You can also provide several inputs at once as a list (separated by semicolons or line-breaks).
76
+
77
+ - Chapter or verse references, in any supported language. Examples:
78
+ - John 3:16
79
+ - Enos 1:13, 15–18
80
+ - Psalm 23
81
+ - Gen. 1:3 (3–4)
82
+ - D&C 20:23; 76:41
83
+ - Scripture publication or book names. Examples:
84
+ - Old Testament
85
+ - Book of Mormon
86
+ - 1 Corinthians
87
+ - Psalms
88
+ - Gospel Library URIs (starting with `/scriptures`). Examples:
89
+ - /scriptures/ot/gen
90
+ - /scriptures/nt/matt/1
91
+ - /scriptures/nt/john/3.16
92
+ - /scriptures/bofm/enos/1.13,15-18
93
+ - /scriptures/pgp
94
+ - Gospel Library URLs (old or new). Examples:
95
+ - https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
96
+ - https://www.churchofjesuschrist.org/study/scriptures/ot?lang=eng
97
+ - http://lds.org/scriptures/bofm/1-ne/3.7?lang=eng
98
+
99
+ ### Options
100
+
101
+ Several options are available. Some are only applicable to certain commands.
102
+
103
+ - **lang** (optional) – Output language. BCP 47 language codes and Gospel Library language codes are supported. Default: 'en'.
104
+ - **separator** (optional) – String separator between outputs when a list of references is being requested. Default: '\n'.
105
+ - **source** (optional) – Content source. Default: 'python-scripture-scraper'. Supported values: 'python-scripture-scraper' or 'ChurchofJesusChrist.org'.
106
+ - **link_class** (optional) – String for the “class” attribute on links. Default: None.
107
+ - **link_target** (optional) – String for the “target” attribute on links. Default: None.
108
+ - **use_query_parameters** (optional) – Whether query parameters should be used on URIs. Default: False.
109
+ - **skip_lang** (optional) – Whether “lang” query parameters should be skipped on URLs. Default: False.
110
+ - **skip_fragment** (optional) – Whether fragments should be skipped on URLs. Default: False.
111
+ - **skip_book_name** (optional) – Whether book names should be skipped on labels. Default: False.
112
+ - **abbreviated** (optional) – Whether book abbrevions should be used on labels. Default: False.
113
+
114
+
115
+ ## Acknowledgements
116
+ [Python Scripture Scraper](https://github.com/samuelbradshaw/python-scripture-scraper) – tool for scraping scripture content and metadata from ChurchofJesusChrist.org.
117
+ [geezify-python](https://github.com/logicalperson0/geezify-python) – tool for converting numbers to and from Geez numerals.
@@ -0,0 +1,2 @@
1
+ requests==2.32.3
2
+ beautifulsoup4==4.12.3
@@ -7,9 +7,10 @@ from . import data, numbers, lookup
7
7
  def main_cli():
8
8
  parser = argparse.ArgumentParser(description='Scripture lookup')
9
9
  parser.add_argument('command', help='Command to run. Required.')
10
- parser.add_argument('--input', help='Input text to parse (one or more references).')
10
+ parser.add_argument('input', help='Input text to parse (one or more references).')
11
11
  parser.add_argument('--lang', help='Output language. Default: "en".')
12
12
  parser.add_argument('--separator', help='Separator when there are multiple results. Default: "\n".')
13
+ parser.add_argument('--source', help='Content source ("python-scripture-scraper" or "ChurchofJesusChrist.org"). Default: "python-scripture-scraper".')
13
14
  parser.add_argument('--link_class', help='Link "class" attribute.')
14
15
  parser.add_argument('--link_target', help='Link "target" attribute.')
15
16
  parser.add_argument('--use_query_parameters', action='store_true', help='Use "id" and "context" parameters in URIs.')
@@ -25,6 +26,7 @@ def main_cli():
25
26
  args.input,
26
27
  lang = args.lang or 'en',
27
28
  separator = args.separator or '\n',
29
+ source = args.source or 'python-scripture-scraper',
28
30
  link_class = args.link_class,
29
31
  link_target = args.link_target,
30
32
  use_query_parameters = args.use_query_parameters,
@@ -0,0 +1,117 @@
1
+ # Python standard libraries
2
+ import os
3
+ import sys
4
+ import json
5
+ import time
6
+
7
+ # Third-party libraries
8
+ import requests
9
+ from bs4 import BeautifulSoup
10
+
11
+
12
+ data_directory = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
13
+ os.makedirs(data_directory, exist_ok = True)
14
+
15
+ # Download JSON data
16
+ def download_data(filename, filepath):
17
+ request_url = f'https://cdn.jsdelivr.net/gh/samuelbradshaw/python-scripture-scraper@main/sample/{filename}'
18
+ r = requests.get(request_url)
19
+ r.encoding = 'utf-8'
20
+ if r and r.status_code == 200:
21
+ data = r.content
22
+ with open(filepath, 'wb') as f:
23
+ f.write(data)
24
+ else:
25
+ sys.exit('\nError: Couldn’t download JSON data:\n{request_url}\n')
26
+
27
+ # Load JSON data
28
+ def load_data(filename):
29
+ filepath = os.path.join(data_directory, filename)
30
+ if os.path.isfile(filepath):
31
+ with open(filepath, 'r', encoding='utf-8') as f:
32
+ return json.load(f)
33
+ else:
34
+ download_data(filename, filepath)
35
+ load_data(filename)
36
+
37
+ # Update JSON data
38
+ def update_data():
39
+ for filename in ('metadata-languages.min.json', 'metadata-scriptures.min.json',):
40
+ download_data(filename, os.path.join(data_directory, filename))
41
+
42
+ languages = load_data('metadata-languages.min.json')
43
+ scriptures = load_data('metadata-scriptures.min.json')
44
+
45
+
46
+ # Get the BCP 47 language tag for a given language code
47
+ def get_bcp47(lang):
48
+ if lang and 'Hant' in lang:
49
+ lang = 'cmn-Hant'
50
+ elif lang and 'Hans' in lang:
51
+ lang = 'cmn-Hans'
52
+
53
+ bcp47 = languages.get('mapToBcp47', {}).get(lang)
54
+ if not bcp47:
55
+ bcp47 = 'en'
56
+ if lang:
57
+ sys.stdout.write(f'Warning: Couldn’t find BCP 47 language tag for “{lang}” – falling back to “en” (English).\n')
58
+
59
+ return bcp47
60
+
61
+
62
+ # Get the content for a given chapter verse from python-scripture-scraper or ChurchofJesusChrist.org
63
+ def request_content(publication_slug, book_slug, chapter, verse_groups, church_url, lang = 'en', source = 'python-scripture-scraper'):
64
+ text_content = ''
65
+
66
+ if not publication_slug and book_slug and chapter:
67
+ return text_content
68
+
69
+ verse_numbers = []
70
+ if verse_groups:
71
+ for verse_group in verse_groups:
72
+ for verse_number in verse_group:
73
+ verse_numbers.append(str(verse_number))
74
+
75
+ if source == 'python-scripture-scraper':
76
+ request_url = f'https://cdn.jsdelivr.net/gh/samuelbradshaw/python-scripture-scraper@main/sample/en-json/{publication_slug}/{book_slug}/{book_slug}-{chapter}.json'
77
+ r = requests.get(request_url)
78
+ r.encoding = 'utf-8'
79
+ if r and r.status_code == 200:
80
+ chapter_data = r.json()
81
+
82
+ if verse_numbers:
83
+ for paragraph in chapter_data['paragraphs']:
84
+ if paragraph['type'] == 'verse' and paragraph['number'] in verse_numbers:
85
+ text_content += paragraph['number'] + ' ' + paragraph['content'] + '\n\n'
86
+ else:
87
+ for paragraph in chapter_data['paragraphs']:
88
+ text_content += (paragraph['number'] + ' ' if paragraph['number'] else '') + paragraph['content'] + '\n\n'
89
+
90
+ text_content += '---------------------\n'
91
+ text_content += 'Source: https://github.com/samuelbradshaw/python-scripture-scraper/tree/main/sample\n'
92
+ text_content += 'Public domain.\n'
93
+
94
+ elif source == 'ChurchofJesusChrist.org' and church_url:
95
+ r = requests.get(church_url)
96
+ r.encoding = 'utf-8'
97
+ if r and r.status_code == 200:
98
+ soup = BeautifulSoup(r.text, 'html.parser')
99
+ paragraphs = soup.select('header [data-aid], .body-block [data-aid]')
100
+ if verse_numbers:
101
+ for paragraph in paragraphs:
102
+ verse_number_span = paragraph.select_one('.verse-number')
103
+ if verse_number_span and verse_number_span.text.strip() in verse_numbers:
104
+ text_content += paragraph.text.strip() + '\n\n'
105
+ else:
106
+ for paragraph in paragraphs:
107
+ text_content += paragraph.text.strip() + '\n\n'
108
+
109
+ text_content += '---------------------\n'
110
+ text_content += f'Source: {church_url}\n'
111
+ text_content += 'Some content from this source may be subject to copyright.\n'
112
+
113
+ # Pause for 1 second between requests to avoid overloading server
114
+ time.sleep(1)
115
+
116
+ return text_content
117
+
@@ -105,11 +105,12 @@ class Reference:
105
105
  return uri
106
106
 
107
107
  # Get the Church website URL (e.g. https://www.churchofjesuschrist.org/study/scriptures/bofm/1-ne/3?id=p7&lang=eng#p7)
108
- # TODO: Add validation based on online availability in the given language
109
108
  def church_url(self, skip_lang = False, skip_fragment = False):
110
109
  url = 'https://www.churchofjesuschrist.org/study'
111
110
  url += self.church_uri(use_query_parameters = True)
112
111
  if not skip_lang:
112
+ if self.lang not in data.scriptures['summary']['churchAvailability'][self.publication_slug]:
113
+ return ''
113
114
  church_lang = data.languages['languages'][self.lang]['churchLang']
114
115
  url += f'&lang={church_lang}' if '?' in url else f'?lang={church_lang}'
115
116
  if self.verse_groups and not skip_fragment:
@@ -127,6 +128,10 @@ class Reference:
127
128
  url = self.church_url(skip_lang = skip_lang, skip_fragment = skip_fragment)
128
129
  return f'<a href="{url}"{additional_attributes}>{label}</a>'
129
130
 
131
+ # Get chapter or verse content
132
+ def content(self, source):
133
+ return data.request_content(self.publication_slug, self.book_slug, self.chapter, self.verse_groups, self.church_url(), lang = self.lang, source = source)
134
+
130
135
  def __str__(self):
131
136
  return label(self)
132
137
 
@@ -273,6 +278,10 @@ def parse_references_string(input_string, lang = 'en'):
273
278
  if book_slug in data.scriptures['structure'].keys():
274
279
  publication_slug = book_slug
275
280
  book_slug = None
281
+ else:
282
+ for pub_slug, pub_data in data.scriptures['structure'].items():
283
+ if book_slug in pub_data['books'].keys():
284
+ publication_slug = pub_slug
276
285
 
277
286
  reference = Reference(lang = lang, publication_slug = publication_slug, book_slug = book_slug, chapter = chapter, verse_groups = verse_groups, context_verse_groups = context_verse_groups)
278
287
  references.append(reference)
@@ -280,6 +289,11 @@ def parse_references_string(input_string, lang = 'en'):
280
289
  return references
281
290
 
282
291
 
292
+ # Functions that can be called via Python or from the command line (see README.md for more information)
293
+
294
+ def get_content(input_string, lang = 'en', separator = '\n', source = 'python-scripture-scraper', **kwargs):
295
+ references = parse_references_string(input_string, lang = lang)
296
+ return separator.join([ref.content(source = source) for ref in references])
283
297
 
284
298
  def get_label(input_string, lang = 'en', separator = '\n', skip_book_name = False, abbreviated = False, **kwargs):
285
299
  references = parse_references_string(input_string, lang = lang)
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.1
2
+ Name: scripturelookup
3
+ Version: 0.0.2
4
+ Summary: Python and command-line utility for converting scripture references between formats.
5
+ Author-email: Samuel Bradshaw <samuel.h.bradshaw@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Samuel Bradshaw
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Repository, https://github.com/samuelbradshaw/python-scripture-lookup
28
+ Project-URL: Issues, https://github.com/samuelbradshaw/python-scripture-lookup/issues
29
+ Project-URL: Changelog, https://github.com/samuelbradshaw/python-scripture-lookup/releases
30
+ Keywords: python,command,scripture,bible,book of mormon,reference
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3
33
+ Requires-Python: >=3.8
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: requests
37
+
38
+ # Scripture Lookup
39
+
40
+ Scripture Lookup is a Python library and command-line tool for looking up scripture verses or chapters. It can also convert scripture references between formats and languages. The tool is built around data from [Python Scripture Scraper](https://github.com/samuelbradshaw/python-scripture-scraper).
41
+
42
+
43
+ ## Installation
44
+
45
+ The Python package and command-line tool can be installed from [PyPI](https://pypi.org/project/scripturelookup/) via pip:
46
+ ```
47
+ pip install scripturelookup
48
+ ```
49
+
50
+
51
+ ## Command-line usage
52
+
53
+ Pattern:
54
+ ```
55
+ scripturelookup [command] [input] [options]
56
+ ```
57
+
58
+ Examples:
59
+ ```
60
+ % scripturelookup get_content "john 3:16" --lang "en"
61
+ 16 ¶ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
62
+
63
+ % scripturelookup get_label "니파이전서 3:7" --lang "fr" --abbreviated
64
+ 1 Né 3:7
65
+
66
+ % scripturelookup get_church_url "helaman 5:12"
67
+ https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
68
+
69
+ % scripturelookup get_label "/scriptures/nt/1-jn/3.2-3" --lang "cmn-Hant"
70
+ 約翰一書3:2-3
71
+
72
+ % scripturelookup get_church_url "/scriptures/ot" --lang "es"
73
+ https://www.churchofjesuschrist.org/study/scriptures/ot?lang=spa
74
+ ```
75
+
76
+
77
+ ## Python usage
78
+
79
+ Examples:
80
+ ```
81
+ from scripturelookup import lookup
82
+
83
+ lookup.get_content('john 3:16', lang = 'en')
84
+ # 16 ¶ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.
85
+
86
+ lookup.get_label('니파이전서 3:7', lang = 'fr', abbreviated = True)
87
+ # 1 Né 3:7
88
+
89
+ lookup.get_church_url('helaman 5:12')
90
+ # https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
91
+
92
+ lookup.get_label('/scriptures/nt/1-jn/3.2-3', lang = 'cmn-Hant')
93
+ # 約翰一書3:2-3
94
+
95
+ lookup.get_church_url('/scriptures/ot', lang = 'es')
96
+ # https://www.churchofjesuschrist.org/study/scriptures/ot?lang=spa
97
+ ```
98
+
99
+
100
+ ## Commands, inputs, and options
101
+
102
+ ### Commands
103
+
104
+ - **get_content** – Get chapter or verse content.
105
+ - **get_label** – Get a scripture reference label (i.e. "John 3:16").
106
+ - **get_church_uri** – Get a Gospel Library URI (i.e. "/scriptures/bofm/hel/5.12").
107
+ - **get_church_url** – Get a Gospel Library URL.
108
+ - **get_church_link** – Get an HTML link to Gospel Library.
109
+
110
+ ### Inputs
111
+
112
+ Any of the following input types are supported. You can also provide several inputs at once as a list (separated by semicolons or line-breaks).
113
+
114
+ - Chapter or verse references, in any supported language. Examples:
115
+ - John 3:16
116
+ - Enos 1:13, 15–18
117
+ - Psalm 23
118
+ - Gen. 1:3 (3–4)
119
+ - D&C 20:23; 76:41
120
+ - Scripture publication or book names. Examples:
121
+ - Old Testament
122
+ - Book of Mormon
123
+ - 1 Corinthians
124
+ - Psalms
125
+ - Gospel Library URIs (starting with `/scriptures`). Examples:
126
+ - /scriptures/ot/gen
127
+ - /scriptures/nt/matt/1
128
+ - /scriptures/nt/john/3.16
129
+ - /scriptures/bofm/enos/1.13,15-18
130
+ - /scriptures/pgp
131
+ - Gospel Library URLs (old or new). Examples:
132
+ - https://www.churchofjesuschrist.org/study/scriptures/bofm/hel/5?id=p12&lang=eng#p12
133
+ - https://www.churchofjesuschrist.org/study/scriptures/ot?lang=eng
134
+ - http://lds.org/scriptures/bofm/1-ne/3.7?lang=eng
135
+
136
+ ### Options
137
+
138
+ Several options are available. Some are only applicable to certain commands.
139
+
140
+ - **lang** (optional) – Output language. BCP 47 language codes and Gospel Library language codes are supported. Default: 'en'.
141
+ - **separator** (optional) – String separator between outputs when a list of references is being requested. Default: '\n'.
142
+ - **source** (optional) – Content source. Default: 'python-scripture-scraper'. Supported values: 'python-scripture-scraper' or 'ChurchofJesusChrist.org'.
143
+ - **link_class** (optional) – String for the “class” attribute on links. Default: None.
144
+ - **link_target** (optional) – String for the “target” attribute on links. Default: None.
145
+ - **use_query_parameters** (optional) – Whether query parameters should be used on URIs. Default: False.
146
+ - **skip_lang** (optional) – Whether “lang” query parameters should be skipped on URLs. Default: False.
147
+ - **skip_fragment** (optional) – Whether fragments should be skipped on URLs. Default: False.
148
+ - **skip_book_name** (optional) – Whether book names should be skipped on labels. Default: False.
149
+ - **abbreviated** (optional) – Whether book abbrevions should be used on labels. Default: False.
150
+
151
+
152
+ ## Acknowledgements
153
+ [Python Scripture Scraper](https://github.com/samuelbradshaw/python-scripture-scraper) – tool for scraping scripture content and metadata from ChurchofJesusChrist.org.
154
+ [geezify-python](https://github.com/logicalperson0/geezify-python) – tool for converting numbers to and from Geez numerals.
@@ -1,40 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: scripturelookup
3
- Version: 0.0.1
4
- Summary: Python and command-line utility for converting scripture references between formats.
5
- Author-email: Samuel Bradshaw <samuel.h.bradshaw@gmail.com>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 Samuel Bradshaw
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
- Project-URL: Repository, https://github.com/samuelbradshaw/python-scripture-lookup
28
- Project-URL: Issues, https://github.com/samuelbradshaw/python-scripture-lookup/issues
29
- Project-URL: Changelog, https://github.com/samuelbradshaw/python-scripture-lookup/releases
30
- Keywords: python,command,scripture,bible,book of mormon,reference
31
- Classifier: License :: OSI Approved :: MIT License
32
- Classifier: Programming Language :: Python :: 3
33
- Requires-Python: >=3.8
34
- Description-Content-Type: text/markdown
35
- License-File: LICENSE
36
- Requires-Dist: requests
37
-
38
- # Scripture Lookup
39
-
40
- TODO: Add readme
@@ -1,3 +0,0 @@
1
- # Scripture Lookup
2
-
3
- TODO: Add readme
@@ -1,3 +0,0 @@
1
- requests
2
-
3
- # -e git+https://github.com/logicalperson0/geezify-python.git@main#egg=geezify-python-main
@@ -1,58 +0,0 @@
1
- # Python standard libraries
2
- import os
3
- import sys
4
- import json
5
-
6
- # Third-party libraries
7
- import requests
8
-
9
-
10
- data_directory = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
11
- os.makedirs(data_directory, exist_ok = True)
12
-
13
- # Download JSON data
14
- def download_data(filename, filepath):
15
- request_url = f'https://raw.githubusercontent.com/samuelbradshaw/python-scripture-scraper/refs/heads/main/sample/{filename}'
16
- r = requests.get(request_url)
17
- r.encoding = 'utf-8'
18
- if r and r.status_code == 200:
19
- data = r.content
20
- with open(filepath, 'wb') as f:
21
- f.write(data)
22
- else:
23
- sys.exit('\nError: Couldn’t download JSON data:\n{request_url}\n')
24
-
25
- # Load JSON data
26
- def load_data(filename):
27
- filepath = os.path.join(data_directory, filename)
28
- if os.path.isfile(filepath):
29
- with open(filepath, 'r', encoding='utf-8') as f:
30
- return json.load(f)
31
- else:
32
- download_data(filename, filepath)
33
- load_data(filename)
34
-
35
- # Update JSON data
36
- def update_data():
37
- for filename in ('metadata-languages.min.json', 'metadata-scriptures.min.json',):
38
- download_data(filename, os.path.join(data_directory, filename))
39
-
40
- languages = load_data('metadata-languages.min.json')
41
- scriptures = load_data('metadata-scriptures.min.json')
42
-
43
-
44
-
45
- # Get the BCP 47 language tag for a given language code
46
- def get_bcp47(lang):
47
- if lang and 'Hant' in lang:
48
- lang = 'cmn-Hant'
49
- elif lang and 'Hans' in lang:
50
- lang = 'cmn-Hans'
51
-
52
- bcp47 = languages.get('mapToBcp47', {}).get(lang)
53
- if not bcp47:
54
- bcp47 = 'en'
55
- if lang:
56
- sys.stdout.write(f'Warning: Couldn’t find BCP 47 language tag for “{lang}” – falling back to “en” (English).\n')
57
-
58
- return bcp47
@@ -1,40 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: scripturelookup
3
- Version: 0.0.1
4
- Summary: Python and command-line utility for converting scripture references between formats.
5
- Author-email: Samuel Bradshaw <samuel.h.bradshaw@gmail.com>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 Samuel Bradshaw
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
- Project-URL: Repository, https://github.com/samuelbradshaw/python-scripture-lookup
28
- Project-URL: Issues, https://github.com/samuelbradshaw/python-scripture-lookup/issues
29
- Project-URL: Changelog, https://github.com/samuelbradshaw/python-scripture-lookup/releases
30
- Keywords: python,command,scripture,bible,book of mormon,reference
31
- Classifier: License :: OSI Approved :: MIT License
32
- Classifier: Programming Language :: Python :: 3
33
- Requires-Python: >=3.8
34
- Description-Content-Type: text/markdown
35
- License-File: LICENSE
36
- Requires-Dist: requests
37
-
38
- # Scripture Lookup
39
-
40
- TODO: Add readme
File without changes