-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText2Morse.py
More file actions
60 lines (52 loc) · 1.79 KB
/
Text2Morse.py
File metadata and controls
60 lines (52 loc) · 1.79 KB
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
import argparse
import os
import sys
class Colors:
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
MAGENTA = '\033[95m'
CYAN = '\033[96m'
RESET = '\033[0m'
os.system('cls' if sys.platform.startswith('win') else 'clear')
morse_code_dict = {
'A': '.-', 'B': '-...',
'C': '-.-.', 'D': '-..', 'E': '.',
'F': '..-.', 'G': '--.', 'H': '....',
'I': '..', 'J': '.---', 'K': '-.-',
'L': '.-..', 'M': '--', 'N': '-.',
'O': '---', 'P': '.--.', 'Q': '--.-',
'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--',
'X': '-..-', 'Y': '-.--', 'Z': '--..',
'0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..',
'9': '----.',
' ': '/'
}
def text_to_morse(text):
morse_code = ''
for char in text.upper():
if char in morse_code_dict:
morse_code += morse_code_dict[char] + ' '
else:
morse_code += char
return morse_code.strip()
def main():
parser = argparse.ArgumentParser(description='Convert text to Morse code.')
parser.add_argument('text', metavar='text', type=str, help='python Text2Morse.py <Text>')
args = parser.parse_args()
result = text_to_morse(args.text)
print(
f"""{Colors.CYAN}
_______ _______ _ _ _______ _______ _____ ______ _______ _______
| |______ \___/ | | | | | | |_____/ |______ |______
| |______ _/ \_ | | | | |_____| | \_ ______| |______
{Colors.RESET}"""
)
print(f'{Colors.BLUE}Text: {args.text}{Colors.RESET}')
print(f'{Colors.GREEN}Morse Code: {result}{Colors.RESET}')
if __name__ == '__main__':
main()