Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbradshaw committed Oct 3, 2024
0 parents commit 344df35
Show file tree
Hide file tree
Showing 19 changed files with 61,708 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.pyc
__pycache__/
.DS_Store*
._*
.Spotlight-V100
.Trashes
Icon?
*~

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Samuel Bradshaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Scripture Lookup

TODO: Add readme
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system]
requires = ["setuptools", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "scripturelookup"
authors = [
{name = "Samuel Bradshaw", email = "[email protected]"},
]
description = "Python and command-line utility for converting scripture references between formats."
readme = "README.md"
license = {file = "LICENSE"}
keywords = ["python", "command", "scripture", "bible", "book of mormon", "reference",]
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.8"
dynamic = ["version"]
dependencies = [
"requests",
]

[project.urls]
Repository = "https://github.com/samuelbradshaw/python-scripture-lookup"
Issues = "https://github.com/samuelbradshaw/python-scripture-lookup/issues"
Changelog = "https://github.com/samuelbradshaw/python-scripture-lookup/releases"

[project.scripts]
scripturelookup = "scripturelookup.command_line:main_cli"

[tool.setuptools_scm]
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests

# -e git+https://github.com/logicalperson0/geezify-python.git@main#egg=geezify-python-main
21 changes: 21 additions & 0 deletions src/geezify-python-main/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Samuel Kenneth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions src/geezify-python-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# geezify-python
A Python Library to convert between Geez and Arabic numbers

Authors:

Yilkal Argaw

Samuel Kenneth
43 changes: 43 additions & 0 deletions src/geezify-python-main/arabify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from re import sub

class Arabify:
"""Converts geez numbers to arab numbers
"""
numbers_dict = {'፩': 1, '፪': 2, '፫': 3, '፬': 4,
'፭': 5, '፮': 6, '፯': 7, '፰': 8,
'፱': 9, '፲': 10, '፳': 20, '፴': 30,
'፵': 40, '፶': 50, '፷': 60, '፸': 70,
'፹': 80, '፺': 90, ' ': 0}

@staticmethod
def arabify(geezNum):
# validate_number
quartets = list(reversed(Arabify.__rollback(geezNum).split('፼')))
num = sum(map
(lambda ntup:
Arabify.__arabify_quartets(ntup[1]) * (10000 ** ntup[0]),
enumerate(quartets)))

return(num)

def __rollback(strgeez):
return(sub(r'^፼', '፩፼', (sub(r'^፻', '፩፻', sub('፼፻', '፼፩፻', strgeez)))))

def __arabify_pairs(geezNum):
"""pairs the geeznums to their arabnums counter parts
"""
# validate_pairs
return(sum([Arabify.numbers_dict[char] for char in geezNum]))

def __arabify_quartets(geezNum):
"""pairs the geeznums to their arabnums counter parts
"""
# validate_quartets
paired = geezNum.split('፻')

if len(paired) == 0:
paired = ['', '']
elif len(paired) == 1:
paired = ['', paired[0]]

return((Arabify.__arabify_pairs(paired[0]) * 100) + Arabify.__arabify_pairs(paired[1]))
13 changes: 13 additions & 0 deletions src/geezify-python-main/arabify_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from arabify import Arabify
from test_data import TESTDATA

class TestArabify(unittest.TestCase):
def test_arabify_for_all_test_cases(self):
for x in TESTDATA:
print(f"{x[1]} => {x[0]}")
print(f"{x[0]} == {Arabify.arabify(x[1])}")
self.assertEqual(x[0], Arabify.arabify(x[1]))

if __name__ == '__main__':
unittest.main()
49 changes: 49 additions & 0 deletions src/geezify-python-main/geezify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Geezify:

@staticmethod
def geezify(number):
return Geezify.__concat_geezified_pairs(Geezify.__geezify_pairs(Geezify.__pairup(number)))

def __pairup(number):
if (type(number) != int):
raise TypeError("not a valid number")
pairs = []

while ((number // 100 != 0) or
(number % 100 != 0)):
pairs.append(number % 100)
number = (number // 100)

return pairs


def __geezify_pairs(pairs):
oneth = ['', '፩', '፪', '፫', '፬', '፭', '፮', '፯', '፰', '፱']
tenth = ['', '፲', '፳', '፴', '፵', '፶', '፷', '፸', '፹', '፺']

geezified_pairs = list(map(lambda num: tenth[num // 10] +
oneth[num % 10],
pairs))

return geezified_pairs


def __concat_geezified_pairs(geezified_pairs):
joined_str = ""
len_gp = len(geezified_pairs)

for i in range(len_gp):
if (i == 0):
joined_str = geezified_pairs[i] + joined_str
elif (i % 2 == 0 and geezified_pairs[i] == "፩" and i == len_gp - 1):
joined_str = "፼" + joined_str
elif (i % 2 == 0):
joined_str = geezified_pairs[i] + "፼" + joined_str
elif (geezified_pairs[i] == "፩"):
joined_str = "፻" + joined_str
elif (geezified_pairs[i] == ""):
continue
else :
joined_str = geezified_pairs[i] + "፻" + joined_str

return joined_str
13 changes: 13 additions & 0 deletions src/geezify-python-main/geezify_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from geezify import Geezify
from test_data import TESTDATA

class TestGeezify(unittest.TestCase):
def test_geezify_for_all_test_cases(self):
for x in TESTDATA:
print(f"{x[0]} => {x[1]}")
print(f"{x[1]} == {Geezify.geezify(x[0])}")
self.assertEqual(x[1], Geezify.geezify(x[0]))

if __name__ == '__main__':
unittest.main()
92 changes: 92 additions & 0 deletions src/geezify-python-main/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
TESTDATA = [
[1, '፩'],
[10, '፲'],
[100, '፻'],
[1000, '፲፻'],
[10000, '፼'], # (እልፍ)
[100000, '፲፼'], # (አእላፍ)
[1000000, '፻፼'], # (አእላፋት)
[10000000, '፲፻፼'], # (ትእልፊት)
[100000000, '፼፼'], # (ትእልፊታት)
[1000000000, '፲፼፼'],
[10000000000, '፻፼፼'],
[100000000000, '፲፻፼፼'], # (ምእልፊት)
[1000000000000, '፼፼፼'], # (ምእልፊታት)
[100010000, '፼፩፼'],
[100100000, '፼፲፼'],
[100200000, '፼፳፼'],
[100110000, '፼፲፩፼'],
[1, '፩'],
[11, '፲፩'],
[111, '፻፲፩'],
[1111, '፲፩፻፲፩'],
[11111, '፼፲፩፻፲፩'],
[111111, '፲፩፼፲፩፻፲፩'],
[1111111, '፻፲፩፼፲፩፻፲፩'],
[11111111, '፲፩፻፲፩፼፲፩፻፲፩'],
[111111111, '፼፲፩፻፲፩፼፲፩፻፲፩'],
[1111111111, '፲፩፼፲፩፻፲፩፼፲፩፻፲፩'],
[11111111111, '፻፲፩፼፲፩፻፲፩፼፲፩፻፲፩'],
[111111111111, '፲፩፻፲፩፼፲፩፻፲፩፼፲፩፻፲፩'],
[1111111111111, '፼፲፩፻፲፩፼፲፩፻፲፩፼፲፩፻፲፩'],
[1, '፩'],
[12, '፲፪'],
[123, '፻፳፫'],
[1234, '፲፪፻፴፬'],
[12345, '፼፳፫፻፵፭'],
[7654321, '፯፻፷፭፼፵፫፻፳፩'],
[17654321, '፲፯፻፷፭፼፵፫፻፳፩'],
[51615131, '፶፩፻፷፩፼፶፩፻፴፩'],
[15161513, '፲፭፻፲፮፼፲፭፻፲፫'],
[10101011, '፲፻፲፼፲፻፲፩'],
[101, '፻፩'],
[1001, '፲፻፩'],
[1010, '፲፻፲'],
[1011, '፲፻፲፩'],
[1100, '፲፩፻'],
[1101, '፲፩፻፩'],
[1111, '፲፩፻፲፩'],
[10001, '፼፩'],
[10010, '፼፲'],
[10100, '፼፻'],
[10101, '፼፻፩'],
[10110, '፼፻፲'],
[10111, '፼፻፲፩'],
[100001, '፲፼፩'],
[100010, '፲፼፲'],
[100011, '፲፼፲፩'],
[100100, '፲፼፻'],
[101010, '፲፼፲፻፲'],
[1000001, '፻፼፩'],
[1000101, '፻፼፻፩'],
[1000100, '፻፼፻'],
[1010000, '፻፩፼'],
[1010001, '፻፩፼፩'],
[1100001, '፻፲፼፩'],
[1010101, '፻፩፼፻፩'],
[101010101, '፼፻፩፼፻፩'],
[100010000, '፼፩፼'],
[100010100, '፼፩፼፻'],
[101010100, '፼፻፩፼፻'],
[3, '፫'],
[30, '፴'],
[33, '፴፫'],
[303, '፫፻፫'],
[3003, '፴፻፫'],
[3030, '፴፻፴'],
[3033, '፴፻፴፫'],
[3300, '፴፫፻'],
[3303, '፴፫፻፫'],
[3333, '፴፫፻፴፫'],
[30003, '፫፼፫'],
[30303, '፫፼፫፻፫'],
[300003, '፴፼፫'],
[303030, '፴፼፴፻፴'],
[3000003, '፫፻፼፫'],
[3000303, '፫፻፼፫፻፫'],
[3030003, '፫፻፫፼፫'],
[3300003, '፫፻፴፼፫'],
[3030303, '፫፻፫፼፫፻፫'],
[303030303, '፫፼፫፻፫፼፫፻፫'],
[333333333, '፫፼፴፫፻፴፫፼፴፫፻፴፫']
]
Empty file added src/scripturelookup/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions src/scripturelookup/command_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Python standard libraries
import argparse

# Internal imports
from . import data, numbers, lookup

def main_cli():
parser = argparse.ArgumentParser(description='Scripture lookup')
parser.add_argument('command', help='Command to run. Required.')
parser.add_argument('--input', help='Input text to parse (one or more references).')
parser.add_argument('--lang', help='Output language. Default: "en".')
parser.add_argument('--separator', help='Separator when there are multiple results. Default: "\n".')
parser.add_argument('--link_class', help='Link "class" attribute.')
parser.add_argument('--link_target', help='Link "target" attribute.')
parser.add_argument('--use_query_parameters', action='store_true', help='Use "id" and "context" parameters in URIs.')
parser.add_argument('--skip_lang', action='store_true', help='Skip "lang" parameter in URLs.')
parser.add_argument('--skip_fragment', action='store_true', help='Skip #frament in URLs.')
parser.add_argument('--skip_book_name', action='store_true', help='Skip scripture book name in labels.')
parser.add_argument('--abbreviated', action='store_true', help='Prefer abbreviated scripture book name in labels.')

args = parser.parse_args()

command = getattr(lookup, args.command)
result = command(
args.input,
lang = args.lang or 'en',
separator = args.separator or '\n',
link_class = args.link_class,
link_target = args.link_target,
use_query_parameters = args.use_query_parameters,
skip_lang = args.skip_lang,
skip_fragment = args.skip_fragment,
skip_book_name = args.skip_book_name,
abbreviated = args.abbreviated
)

print(result)
Loading

0 comments on commit 344df35

Please sign in to comment.