From 6e77f20c1ea0434e0df982eef046bf07484ea2a7 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Mon, 24 Jun 2024 14:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E6=9C=9F=E7=B1=BB?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_review/util/data_util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/photo_review/util/data_util.py b/photo_review/util/data_util.py index dd26895..76ea4fc 100644 --- a/photo_review/util/data_util.py +++ b/photo_review/util/data_util.py @@ -27,8 +27,8 @@ def handle_date(string): string = string.replace("年", "-").replace("月", "-").replace("日", "").replace("/", "-").replace(".", "-") string = re.sub(r'[^0-9-]', '', string) + string = string.strip("-") if "-" in string: - string = string.strip("-") dash_count = string.count("-") if dash_count > 2: third_dash_index = string.find("-", string.find("-", string.find("-") + 1) + 1) @@ -118,3 +118,7 @@ def handle_original_data(string): return "" # 防止过长存入数据库失败 return string[:255] + + +if __name__ == '__main__': + print(handle_date("2024年"))