-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from resnickmicah/add-argparse
Disable printing letters before spelling by default (activate with -v), add support for the second alphabet.
- Loading branch information
Showing
3 changed files
with
137 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setup( | ||
name='spell-it-for-me', | ||
version='0.1.1', | ||
version='0.2.1', | ||
url='https://github.com/bondarevts/spell-it-for-me', | ||
author='Timofei Bondarev', | ||
author_email='[email protected]', | ||
|
@@ -18,10 +18,7 @@ | |
classifiers=[ | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,110 @@ | ||
#!/usr/bin/env python | ||
from __future__ import print_function | ||
import argparse | ||
|
||
import sys | ||
from typing import Dict | ||
|
||
law_enforcement_spelling = { | ||
'a': 'Adam', | ||
'b': 'Boston', | ||
'c': 'Charles', | ||
'd': 'David', | ||
'e': 'Edward', | ||
'f': 'Frank', | ||
'g': 'George', | ||
'h': 'Henry', | ||
'i': 'Ida', | ||
'j': 'James', | ||
'k': 'King', | ||
'l': 'Lincoln', | ||
'm': 'Mary', | ||
'n': 'Nora', | ||
'o': 'Oscar', | ||
'p': 'Paul', | ||
'q': 'Queen', | ||
'r': 'Robert', | ||
's': 'Sam', | ||
't': 'Tom', | ||
'u': 'Union', | ||
'v': 'Victor', | ||
'w': 'William', | ||
'x': 'X-Ray', | ||
'y': 'Young', | ||
'z': 'Zebra', | ||
police_spelling = { | ||
"a": "Adam", | ||
"b": "Boston", | ||
"c": "Charles", | ||
"d": "David", | ||
"e": "Edward", | ||
"f": "Frank", | ||
"g": "George", | ||
"h": "Henry", | ||
"i": "Ida", | ||
"j": "James", | ||
"k": "King", | ||
"l": "Lincoln", | ||
"m": "Mary", | ||
"n": "Nora", | ||
"o": "Oscar", | ||
"p": "Paul", | ||
"q": "Queen", | ||
"r": "Robert", | ||
"s": "Sam", | ||
"t": "Tom", | ||
"u": "Union", | ||
"v": "Victor", | ||
"w": "William", | ||
"x": "X-Ray", | ||
"y": "Young", | ||
"z": "Zebra", | ||
} | ||
|
||
nato_spelling = { | ||
'a': 'Álfa', | ||
'b': 'Brávo', | ||
'c': 'Chárlie', | ||
'd': 'Délta', | ||
'e': 'Écho', | ||
'f': 'Fóxtrot', | ||
'g': 'Gólf', | ||
'h': 'Hotél', | ||
'i': 'Índia', | ||
'j': 'Júliett', | ||
'k': 'Kílo', | ||
'l': 'Líma', | ||
'm': 'Mike', | ||
'n': 'Novémber', | ||
'o': 'Óscar', | ||
'p': 'Papá', | ||
'q': 'Quebéc', | ||
'r': 'Rómeo', | ||
's': 'Siérra', | ||
't': 'Tángo', | ||
'u': 'Úniform', | ||
'v': 'Víctor', | ||
'w': 'Whísky', | ||
'x': 'X-ray', | ||
'y': 'Yánkee', | ||
'z': 'Zúlu' | ||
"a": "Álfa", | ||
"b": "Brávo", | ||
"c": "Chárlie", | ||
"d": "Délta", | ||
"e": "Écho", | ||
"f": "Fóxtrot", | ||
"g": "Gólf", | ||
"h": "Hotél", | ||
"i": "Índia", | ||
"j": "Júliett", | ||
"k": "Kílo", | ||
"l": "Líma", | ||
"m": "Mike", | ||
"n": "Novémber", | ||
"o": "Óscar", | ||
"p": "Papá", | ||
"q": "Quebéc", | ||
"r": "Rómeo", | ||
"s": "Siérra", | ||
"t": "Tángo", | ||
"u": "Úniform", | ||
"v": "Víctor", | ||
"w": "Whísky", | ||
"x": "X-ray", | ||
"y": "Yánkee", | ||
"z": "Zúlu", | ||
} | ||
|
||
parser = argparse.ArgumentParser( | ||
description="A simple command line tool " | ||
"to display a spelling for any phrase " | ||
"using a phonetic alphabet." | ||
) | ||
parser.add_argument( | ||
"--alphabet", | ||
"-a", | ||
default="nato", | ||
choices=["nato", "police"], | ||
dest="alphabet", | ||
help="Defaults to NATO phonetic alphabet: Álfa Brávo Chárlie..., " | ||
"can also use police: Adam Boston Charles...", | ||
) | ||
parser.add_argument( | ||
"--verbose", | ||
"-v", | ||
action="store_true", | ||
dest="verbose", | ||
help="Print the original letter before each phonetic alphabet word", | ||
) | ||
parser.add_argument( | ||
dest="phrase", | ||
nargs="+", | ||
help="The word or phrase you want to spell using a phonetic alphabet", | ||
) | ||
|
||
|
||
def print_spelling(word: str, spelling_map: Dict[str, str]) -> None: | ||
for letter in word: | ||
print(letter, ': ', sep='', end='') | ||
def print_spelling(args: argparse.ArgumentParser) -> None: | ||
if args.alphabet == "nato": | ||
spelling_map = nato_spelling | ||
elif args.alphabet == "police": | ||
spelling_map = police_spelling | ||
else: | ||
raise ValueError(f"Improper alphabet arg, must be {args.alphabet.choices}") | ||
for letter in " ".join(args.phrase): | ||
if args.verbose: | ||
print(letter, ": ", sep="", end="") | ||
print(spelling_map.get(letter.lower(), letter)) | ||
|
||
|
||
def main() -> None: | ||
phrase = ' '.join(sys.argv[1:]) | ||
print_spelling(phrase, nato_spelling) | ||
args = parser.parse_args() | ||
print_spelling(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
main() |