sync moved to modules

This commit is contained in:
tmshv committed 2020-02-23 21:25:17 +03:00
1 parent 1dda6ce8cc
commit 13b761a81e
50 files changed

No files matched your search

+94
View File
@@ -0,0 +1,94 @@
import re
from unidecode import unidecode
from utils.fn import compose
remove_pattr = re.compile('[«»<>#,!&"\']')
reduce_dash_patterns = [
(re.compile('[-]+'), '-'),
(re.compile('^-'), '')
]
def translit(text):
"""
RUSSIAN TEXT => ENGLISH TEXT
"""
return unidecode(text)
def interpolate(text, storage, key_fn=None):
if not key_fn:
key_fn = lambda i: i
key = key_fn(text)
return storage[key] if key in storage else text
def interpolate_swift(i):
return re.search("([\d\w-]+)", i).group(1)
def remove_punctuation(i):
return remove_pattr.sub('', i)
def reduce_dashes(i):
value = i
for reg_exp, replace in reduce_dash_patterns:
value = reg_exp.sub(replace, value)
return value
def space_to_dash(i):
return i.replace(' ', '-')
def short_dash(i):
"""
minus -> dash
tire -> dash
:param i:
:return:
"""
return i.replace('–', '-').replace('—', '-')
def dot_to_dash(i):
return i.replace('.', '-')
def slash_to_dash(i):
return i.replace('/', '-')
def remove_underscores(i):
return i.replace('_', '')
def text_lower(i):
return i.lower()
url_encode_file = compose(
translit,
space_to_dash,
short_dash,
remove_underscores,
remove_punctuation,
reduce_dashes,
text_lower,
)
url_encode_text = compose(
translit,
space_to_dash,
dot_to_dash,
short_dash,
slash_to_dash,
remove_underscores,
remove_punctuation,
reduce_dashes,
text_lower,
)