From 90c4463c5f98b00fed55db38e15b2e2e375ce12d Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Fri, 14 Jul 2023 07:18:23 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Removed=20invalid=20char=20in=20?= =?UTF-8?q?output=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.py | 4 ++-- src/utils.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/parser.py b/src/parser.py index a1bee8e..e5694c4 100644 --- a/src/parser.py +++ b/src/parser.py @@ -8,7 +8,7 @@ from loguru import logger from src.config import RevancedConfig from src.patches import Patches -from src.utils import possible_archs +from src.utils import possible_archs, slugify class Parser(object): @@ -100,7 +100,7 @@ class Parser(object): "-m", integrations, "-o", - f"Re-{app}-{version}{output_prefix}output.apk", + f"Re-{app}-{slugify(version)}{output_prefix}output.apk", "--keystore", self.config.keystore_name, "--options", diff --git a/src/utils.py b/src/utils.py index 497725a..1cb7ad0 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,4 +1,5 @@ """Utilities.""" +import re from typing import Dict from loguru import logger @@ -55,3 +56,23 @@ def handle_response(response: Response) -> None: if response_code != 200: logger.error(response.text) exit(1) + + +def slugify(string: str) -> str: + """Converts a string to a slug format.""" + # Convert to lowercase + string = string.lower() + + # Remove special characters + string = re.sub(r"[^\w\s-]", "", string) + + # Replace spaces with dashes + string = re.sub(r"\s+", "-", string) + + # Remove consecutive dashes + string = re.sub(r"-+", "-", string) + + # Remove leading and trailing dashes + string = string.strip("-") + + return string