Created
May 31, 2020 17:50
-
-
Save Alababdiy/3cad4cb962c0f18cfb27acfa6129c20b to your computer and use it in GitHub Desktop.
plate translation
This file contains hidden or 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
def english_plat(number: str, chars: str): | |
# https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Saudi_Arabia | |
numbers_map = { | |
'١': '1', '٢': '2', '٣': '3', | |
'٤': '4', '٥': '5', '٦': '6', | |
'٧': '7', '٨': '8', '٩': '9', | |
'٠': '0', | |
} | |
for k, v in numbers_map.items(): | |
number = re.sub(k, v, number) | |
chars_map = { | |
'ا': 'A', | |
'ب': 'B', | |
'ح': 'J', | |
'د': 'D', | |
'ر': 'R', | |
'س': 'S', | |
'ص': 'X', | |
'ط': 'T', | |
'ع': 'E', | |
'ق': 'G', | |
'ك': 'K', | |
'ل': 'L', | |
'م': 'Z', | |
'ن': 'N', | |
'هـ': 'H', | |
'و': 'U', | |
'ى': 'V', | |
} | |
for k, v in chars_map.items(): | |
chars = re.sub(k, v, chars) | |
return number, chars[::-1] | |
def arabic_plat(number: str, chars: str): | |
# https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Saudi_Arabia | |
numbers_map = { | |
'1': '١', | |
'2': '٢', | |
'3': '٣', | |
'4': '٤', | |
'5': '٥', | |
'6': '٦', | |
'7': '٧', | |
'8': '٨', | |
'9': '٩', | |
'0': '٠', | |
} | |
for k, v in numbers_map.items(): | |
number = re.sub(k, v, number) | |
chars_map = { | |
'A': 'ا', | |
'B': 'ب', | |
'J': 'ح', | |
'D': 'د', | |
'R': 'ر', | |
'S': 'س', | |
'X': 'ص', | |
'T': 'ط', | |
'E': 'ع', | |
'G': 'ق', | |
'K': 'ك', | |
'L': 'ل', | |
'Z': 'م', | |
'N': 'ن', | |
'H': 'هـ', | |
'U': 'و', | |
'V': 'ى', | |
} | |
for k, v in chars_map.items(): | |
chars = re.sub(k, v, chars) | |
return number, chars[::-1] | |
def check_plat(number: str, chars: str): | |
if not number.isdigit(): | |
return False, '{"status": false, "reason": "UNCORRECTED_PLAT_FORMAT"}' | |
for c in chars: | |
if c not in ['A', 'B', 'J', 'D', 'R', 'S', 'X', 'T', 'E', 'G', 'K', 'L', 'Z', 'N', 'H', 'U', 'V', ]: | |
return False, '{"status": false, "reason": "UNCORRECTED_PLAT_FORMAT"}' | |
return f'{number} {chars}', '' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment