Last active
March 12, 2019 07:37
-
-
Save dorukcan/de40ce86942dcbb30064db917b591501 to your computer and use it in GitHub Desktop.
This file contains 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 make_turkish(text, encode=False): | |
""" | |
Transforms a broken text to nice unicode equivalent. | |
:param text: Text to modify | |
:param encode: Boolean value indicates that whether encode the text to utf-8 or not | |
:return: Modified text | |
""" | |
if not text: | |
return None | |
if encode is True: | |
text = text.encode('latin1').decode('utf-8', 'backslashreplace') | |
tr_map = { | |
'\\xa0': ' ', | |
'\xa0': ' ', | |
'\t': ' ', | |
" ": "", | |
" ": "", | |
"¡": "¡", | |
"¡": "¡", | |
"¢": "¢", | |
"¢": "¢", | |
"£": "£", | |
"£": "£", | |
"¤": "¤", | |
"¤": "¤", | |
"¥": "¥", | |
"¥": "¥", | |
"¦": "¦", | |
"¦": "¦", | |
"§": "§", | |
"§": "§", | |
"¨": "¨", | |
"¨": "¨", | |
"©": "©", | |
"ª": "ª", | |
"ª": "ª", | |
"«": "«", | |
"«": "«", | |
"¬": "¬", | |
"¬": "¬", | |
"­": "", | |
"­": "", | |
"¯": "¯", | |
"¯": "¯", | |
"°": "°", | |
"°": "°", | |
"±": "±", | |
"±": "±", | |
"²": "²", | |
"²": "²", | |
"³": "³", | |
"³": "³", | |
"´": "´", | |
"´": "´", | |
'•': '•', | |
'“': '“', | |
'â€': '”', | |
'‘': '‘', | |
'’': '’', | |
'ݾ': 'İ', | |
'Ý': 'İ', | |
'Ä°': 'İ', | |
'Ã': 'İ', | |
'‹': 'İ', | |
'Ý': 'İ', | |
'ý': 'ı', | |
'ı': 'ı', | |
'±': 'ı', | |
'ý': 'ı', | |
'Û': 'ı', | |
'›': 'ı', | |
'ý': 'ı', | |
'Þ': 'Ş', | |
'Åž': 'Ş', | |
'ÅŸ': 'Ş', | |
'åÿ': 'Ş', | |
'Þ': 'Ş', | |
'þ': 'ş', | |
'Å?': 'ş', | |
'ÅŸ': 'ş', | |
'þ': 'ş', | |
'Å\x9f': 'ş', | |
'Ð': 'Ğ', | |
'Äž': 'Ğ', | |
'ð': 'ğ', | |
'Ä?': 'ğ', | |
'ÄŸ': 'ğ', | |
'ð': 'ğ', | |
'Ä\x9f': 'ğ', | |
'Ç': 'Ç', | |
'Ã?': 'Ç', | |
'Ç': 'Ç', | |
'ç': 'ç', | |
'ç': 'ç', | |
'Ö': 'Ö', | |
'Ö': 'Ö', | |
'ö': 'ö', | |
'ö': 'ö', | |
'Ãœ': 'Ü', | |
'Ü': 'Ü', | |
'ü': 'ü', | |
'ã¼': 'ü', | |
'ü': 'ü', | |
'ü': 'ü', | |
"©": "©", | |
"©": "©", | |
"©": "©", | |
"®": "®", | |
"®": "®", | |
"®": "®", | |
"®": "®", | |
"®": "®", | |
"™": "™", | |
"™": "™", | |
"™": "™", | |
"™": "™", | |
">": ">", | |
">": ">", | |
">": ">", | |
">": ">", | |
"<": "<", | |
"<": "<", | |
"<": "<", | |
"<": "<", | |
";": ";", | |
";": ";", | |
";": ";", | |
"&": "&", | |
"&": "&", | |
"&": "&", | |
"&": "&", | |
""": '"', | |
""": '"', | |
""": '"', | |
""": '"', | |
"#": "#", | |
"#": "#", | |
"#": "#", | |
"€": "€", | |
"â\x80\x99": "'", | |
"â\x80\x9d": '"', | |
} | |
for key, value in tr_map.items(): | |
text = text.replace(key, value) | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment