aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--paper2remarkable/providers/_info.py1
-rw-r--r--paper2remarkable/utils.py8
2 files changed, 6 insertions, 3 deletions
diff --git a/paper2remarkable/providers/_info.py b/paper2remarkable/providers/_info.py
index 9130e34..0b28658 100644
--- a/paper2remarkable/providers/_info.py
+++ b/paper2remarkable/providers/_info.py
@@ -56,6 +56,7 @@ class Informer:
title = clean_string(self.title)
title = titlecase.titlecase(title)
title = title.replace(" ", "_")
+ title = clean_string(title)
year = str(self.year)
diff --git a/paper2remarkable/utils.py b/paper2remarkable/utils.py
index d80c954..a313ffe 100644
--- a/paper2remarkable/utils.py
+++ b/paper2remarkable/utils.py
@@ -28,6 +28,7 @@ HEADERS = {
logger = Logger()
+
def exception(msg):
print("ERROR: " + msg, file=sys.stderr)
print("Error occurred. Exiting.", file=sys.stderr)
@@ -39,14 +40,15 @@ def exception(msg):
raise SystemExit(1)
-
def clean_string(s):
""" Clean a string by replacing accented characters with equivalents and
keeping only the allowed characters (ascii letters, digits, underscore,
- space, and period)"""
+ space, dash, and period)"""
normalized = unidecode.unidecode(s)
- allowed = string.ascii_letters + string.digits + "_ ."
+ allowed = string.ascii_letters + string.digits + "_ .-"
cleaned = "".join(c if c in allowed else "_" for c in normalized)
+ while "__" in cleaned:
+ cleaned = cleaned.replace("__", "_")
return cleaned