Skip to content

Commit

Permalink
Merge pull request #1 from resnickmicah/add-argparse
Browse files Browse the repository at this point in the history
Disable printing letters before spelling by default (activate with -v), add support for the second alphabet.
  • Loading branch information
bondarevts authored Dec 28, 2020
2 parents 2189b99 + 9909c3a commit 7c0e238
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 69 deletions.
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Spell It For Me
A simple command line tool to display a spelling for any phrase using a phonetic alphabet.

Uses the NATO phonetic alphabet.
Can use NATO (`-a nato`, active by default) or law enforcement (`-a police`) phonetic alphabets.

More alphabets will be supported in the future.
More alphabets might be supported in the future.

## Installation

Expand All @@ -15,8 +15,47 @@ $ pip install spell-it-for-me

## Usage

By default `spell` will print every letter spelled on a separate line using the NATO phonetic alphabet:
```bash
$ spell Louis
$ spell Louis
Líma
Óscar
Úniform
Índia
Siérra
```

Spelling phrases of several words is supported:
```bash
$ spell Worcester, MA
Whísky
Óscar
Rómeo
Chárlie
Écho
Siérra
Tángo
Écho
Rómeo
,

Mike
Álfa
```

Law enforcement alphabet is available (use `-a police` or `--alphabet police`):
```bash
$ spell -a police Louis
Lincoln
Oscar
Union
Ida
Sam
```

Use `-v` (or `--verbose`) to print each letter used for spelling:
```bash
spell.py -v Louis
L: Líma
o: Óscar
u: Úniform
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]',
Expand All @@ -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',
Expand Down
156 changes: 94 additions & 62 deletions src/spell.py
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()

0 comments on commit 7c0e238

Please sign in to comment.