sync moved to modules
This commit is contained in:
1 parent
1dda6ce8cc
commit
13b761a81e
50 files changed
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
|
||||
import math
|
||||
|
||||
|
||||
def default_ext(ext: str):
|
||||
return ext.upper()
|
||||
|
||||
|
||||
def get_ext(filename):
|
||||
ext_s = ['.png', '.pdf', '.jpg', '.jpeg', '.gif', '.doc']
|
||||
ext_d = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК']
|
||||
|
||||
_, ext = os.path.splitext(filename)
|
||||
|
||||
if ext in ext_s:
|
||||
i = ext_s.index(ext)
|
||||
return ext_d[i]
|
||||
else:
|
||||
default_ext(ext)
|
||||
|
||||
|
||||
def get_size(number_of_bytes, precision=1):
|
||||
units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ']
|
||||
|
||||
number = math.floor(math.log(number_of_bytes) / math.log(1024))
|
||||
size = (number_of_bytes / math.pow(1024, math.floor(number)))
|
||||
size = round(size, precision)
|
||||
return f'{size} {units[number]}'
|
||||
@@ -0,0 +1,18 @@
|
||||
from utils.fn import until
|
||||
|
||||
|
||||
def split(data, separator=' '):
|
||||
try:
|
||||
s = data.index(separator)
|
||||
return data[:s], data[s:]
|
||||
except ValueError:
|
||||
return None, None
|
||||
|
||||
|
||||
def split_with(separators):
|
||||
return lambda data: until(
|
||||
lambda i: i[0] and i[1],
|
||||
lambda s: split(data, s),
|
||||
separators,
|
||||
(None, None)
|
||||
)
|
||||
@@ -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,
|
||||
)
|
||||
Reference in new issue
Block a user