forked from maximromanov/ArabicBetacode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_gBC.py
109 lines (74 loc) · 3.53 KB
/
_gBC.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os, re
import betaCode, betaCodeTables
import argparse
import sys
import io
def translitArabic():
text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()
if(getattr(args, 'delimited') != None):
text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.arabicToBetaCode(match.group(1)), text, flags=re.DOTALL)
else:
text = betaCode.arabicToBetaCode(text)
sys.stdout.buffer.write(text.encode('utf8'))
def translitOTO():
text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()
if(getattr(args, 'delimited') != None):
text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.betacodeToTranslit(match.group(1)), text, flags=re.DOTALL)
else:
text = betaCode.betacodeToTranslit(text)
sys.stdout.buffer.write(text.encode('utf8'))
def translitLOC():
text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()
if(getattr(args, 'delimited') != None):
text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.betacodeToLOC(match.group(1)), text, flags=re.DOTALL)
else:
text = betaCode.betacodeToLOC(text)
sys.stdout.buffer.write(text.encode('utf8'))
def translitToSearch():
text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()
if(getattr(args, 'delimited') != None):
text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.betacodeToSearch(match.group(1)), text, flags=re.DOTALL)
else:
text = betaCode.betacodeToSearch(text)
sys.stdout.buffer.write(text.encode('utf8'))
def translitToArabic():
text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()
if(getattr(args, 'delimited') != None):
text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.betacodeToArabic(match.group(1)), text, flags=re.DOTALL)
else:
text = betaCode.betacodeToArabic(text)
sys.stdout.buffer.write(text.encode('utf8'))
def translitToArSimple():
text = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8').read()
if(getattr(args, 'delimited') != None):
text = re.sub(r"(?<!\\)%(.*?)(?<!\\)%", lambda match: betaCode.betaCodeToArSimple(match.group(1)), text, flags=re.DOTALL)
else:
text = betaCode.betaCodeToArSimple(text)
sys.stdout.buffer.write(text.encode('utf8'))
parser = argparse.ArgumentParser()
parser.add_argument('--translitArabic', action='store_const', const=translitArabic)
parser.add_argument('--translitOTO', action='store_const', const=translitOTO)
parser.add_argument('--translitLOC', action='store_const', const=translitLOC)
parser.add_argument('--translitToSearch', action='store_const', const=translitToSearch)
parser.add_argument('--translitToArabic', action='store_const', const=translitToArabic)
parser.add_argument('--translitToArSimple', action='store_const', const=translitToArSimple)
parser.add_argument('--delimited', action='store_const', const='delimited')
args = parser.parse_args()
translitArabic = getattr(args, 'translitArabic')
translitOTO = getattr(args, 'translitOTO')
translitLOC = getattr(args, 'translitLOC')
translitToSearch = getattr(args, 'translitToSearch')
translitToArabic = getattr(args, 'translitToArabic')
translitToArSimple = getattr(args, 'translitToArSimple')
if(translitArabic != None):
args.translitArabic()
elif(translitOTO != None):
args.translitOTO()
elif(translitLOC != None):
args.translitLOC()
elif(translitToSearch != None):
args.translitToSearch()
elif(translitToArabic != None):
args.translitToArabic()
elif(translitToArSimple != None):
args.translitToArSimple()