-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBraille.py
70 lines (57 loc) · 3.46 KB
/
Braille.py
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
61
62
63
64
65
66
67
68
69
70
banner = """\u001b[36;1m
█████▄ ██▀███ ▄▄▄ ▄████ ▒█████ ███▄ ▄███ ▄███ ▓▓▄ █
▒██ ██▌▓██ ▒ ██▒▒████▄ ██▒ ▀█▒▒██ ██▒ ██▒▀█▀█ █ ▒██ ██ ▄ ██ ▀█ █
░██ █▌▓██ ▄█ ▒▒██ ▀█▄ ▒██░▄▄▄░▒██░ ██ ▓██ ▓██▒ ██ ▀█▄▓ ██ ▀█ ██▒
░▓█▄ ▌▒██▀▀█▄ ░██▄▄▄▄██ ░▓█ ██▓▒██ ██░▒██ ▒██ ░██▄▄▄▄██ ▓██▒ ▐▌██▒
░▒████▓ ░██▓ ▒██▒ ▓█ ▓██▒░▒▓███▀▒░ ████▓▒░▒██▒ ░██▒ ▓█ ▓██▒▒██░ ▓██░
▒▒▓ ▒ ░ ▒▓ ░▒▓░ ▒▒ ▒█░ ░▒ ▒ ░ ▒░▒░▒░ ░ ▒░ ░ ░ ▒▒ ▓▒█░░ ▒░ ▒ ▒
░ ▒ ▒ ░▒ ░ ▒░ ▒ ▒▒ ░ ░ ░ ░ ▒ ▒░ ░ ░ ░ ▒ ▒▒ ░░ ░░ ░ ▒░
░ ░ ░ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
\u001b[32;1m
--Presented with <3 by Shivanshu Sharma
\u001b[35
█▄─▄─▀█▄─▄▄▀██▀▄─██▄─▄█▄─▄███▄─▄███▄─▄▄─█
██─▄─▀██─▄─▄██─▀─███─███─██▀██─██▀██─▄█▀█
▀▄▄▄▄▀▀▄▄▀▄▄▀▄▄▀▄▄▀▄▄▄▀▄▄▄▄▄▀▄▄▄▄▄▀▄▄▄▄▄▀
\u001b[32;1m \u001b[0m """
print(banner)
from __future__ import unicode_literals
import optparse
alphabraille = ['⠁', '⠃', '⠉', '⠙', '⠑', '⠋', '⠛', '⠓', '⠊', '⠚', '⠅', '⠇',
'⠍', '⠝', '⠕', '⠏', '⠟', '⠗', '⠎', '⠞', '⠥', '⠧', '⠺', '⠭', '⠽', '⠵']
numbraille = ['⠼⠁', '⠼⠃', '⠼⠉', '⠼⠙', '⠼⠑', '⠼⠋', '⠼⠛', '⠼⠓', '⠼⠊', '⠼⠚']
alphabet = ['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']
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
enc = None
dec = None
usage = "usage: %prog -arg"
parser = optparse.OptionParser(usage=usage)
parser.add_option('-e', dest="enc", type="string", help="enc plain text to Braille")
parser.add_option('-d', dest="dec", type="string", help="dec Braille into plain text")
(options, args) = parser.parse_args()
if not options:
parser.error("incorrect number of arguments")
if options.enc:
enc = options.enc
if options.dec:
dec = options.dec.decode('utf8', 'ignore')
def main():
s = ""
if enc:
for n in enc:
if n in alphabet:
s += alphabraille[alphabet.index(n)]
elif n in nums:
s += numbraille[nums.index(n)]
print(s)
return
if dec:
for n in dec:
if n in alphabraille:
s += alphabet[alphabraille.index(n)]
print(s)
return
if __name__ == "__main__":
main()