aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
Diffstat (limited to 'uploader')
-rw-r--r--uploader/datautils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/uploader/datautils.py b/uploader/datautils.py
index e593937..2ee079d 100644
--- a/uploader/datautils.py
+++ b/uploader/datautils.py
@@ -26,3 +26,13 @@ def order_by_family(items: tuple[dict, ...],
return sorted(tuple(reduce(__order__, items, {}).items()),
key=lambda item: item[0][0])
+
+
+def safe_int(val: str) -> int:
+ """
+ Convert val into an integer: if val cannot be converted, return a zero.
+ """
+ try:
+ return int(val)
+ except ValueError:
+ return 0