Skip to content

Commit

Permalink
fix: better pattern substitution for non alphanumeric characters in f…
Browse files Browse the repository at this point in the history
…ile names
  • Loading branch information
chrisjohnson00 committed Apr 8, 2021
1 parent 596bba3 commit 8b72b32
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9.1-slim
FROM python:3.9.4-slim

WORKDIR /usr/src/app

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ To use local config values, instead of consul, just export the config, for examp

## Dependencies

- https://pypi.org/project/kubernetes/
- https://pypi.org/project/prometheus-client/
- https://pypi.org/project/python-consul/
pip install --upgrade pip
pip install --upgrade pygogo python-consul kubernetes prometheus-client
pip freeze > requirements.txt
sed -i '/pkg-resources/d' requirements.txt
7 changes: 7 additions & 0 deletions app/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ def test_cleanup_job_suffix_accents():
assert result == expected_result


def test_cleanup_job_suffix_accents_2():
input_with_accent_character = "The Man in the High Castle - S03E03 - Sensō Kōi WEBDL-1080p Proper REAL"
expected_result = "themaninthehighcastles03e03senskiwebdl1080pproperreal"
result = cleanup_job_suffix(input_with_accent_character)
assert result == expected_result


def test_cleanup_job_suffix_period():
input_with_period_character = "The.Panty.Piata.Polarization.HDTV-1080p"
expected_result = "thepantypiatapolarizationhdtv1080p"
Expand Down
10 changes: 4 additions & 6 deletions app/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import re
from string import ascii_letters, digits


def cleanup_job_suffix(input_string):
# keep only word character, removing all non-word chars
job_suffix = re.sub(r"\W", "", input_string.lower(), flags=re.I)
job_suffix = re.sub(r"[à-ú]|[À-Ú]", "", job_suffix, flags=re.I)
job_suffix = job_suffix.replace("_", "")
return job_suffix
# keep only a-z and 0-9
job_suffix = "".join([ch for ch in input_string if ch in (ascii_letters + digits)])
return job_suffix.lower()
34 changes: 9 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
attrs==20.3.0
cachetools==4.2.0
cachetools==4.2.1
certifi==2020.12.5
chardet==3.0.4
flake8==3.8.4
google-auth==1.24.0
chardet==4.0.0
google-auth==1.28.1
idna==2.10
importlib-metadata==3.3.0
iniconfig==1.1.1
kubernetes==12.0.1
mccabe==0.6.1
more-itertools==8.6.0
oauthlib==3.1.0
packaging==20.8
pluggy==0.13.1
prometheus-client==0.9.0
py==1.10.0
prometheus-client==0.10.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.6.0
pyflakes==2.2.0
pyparsing==2.4.7
pytest==6.2.1
pygogo==0.13.2
python-consul==1.1.0
python-dateutil==2.8.1
PyYAML==5.3.1
PyYAML==5.4.1
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.6
rsa==4.7.2
six==1.15.0
toml==0.10.2
typing-extensions==3.7.4.3
urllib3==1.26.2
wcwidth==0.2.5
websocket-client==0.57.0
zipp==3.4.0
urllib3==1.26.4
websocket-client==0.58.0

0 comments on commit 8b72b32

Please sign in to comment.