优化与调整
This commit is contained in:
@@ -6,7 +6,12 @@ from datetime import datetime
|
||||
def handle_decimal(string):
|
||||
if not string:
|
||||
return ""
|
||||
return re.sub(r'[^0-9.]', '', string)
|
||||
string = re.sub(r'[^0-9.]', '', string)
|
||||
front, back = string.rsplit('.', 1)
|
||||
front = front.replace(".", "")
|
||||
if back:
|
||||
back = "." + back
|
||||
return front + back
|
||||
|
||||
|
||||
# 处理日期类数据
|
||||
@@ -14,8 +19,13 @@ def handle_date(string):
|
||||
if not string:
|
||||
return ""
|
||||
|
||||
string = string.replace("年", "-").replace("月", "-").replace("日", "")
|
||||
string = string.replace("年", "-").replace("月", "-").replace("日", "").replace("/", "-").replace(".", "-")
|
||||
string = re.sub(r'[^0-9-]', '', string)
|
||||
length = len(string)
|
||||
if length > 8 and "-" not in string:
|
||||
string = string[:8]
|
||||
elif length > 10 and "-" in string:
|
||||
string = string[:10]
|
||||
if is_valid_date_format(string):
|
||||
return string
|
||||
else:
|
||||
@@ -48,3 +58,20 @@ def is_valid_date_format(date_str):
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def handle_department(string):
|
||||
result = []
|
||||
if not string:
|
||||
return result
|
||||
result.append(string)
|
||||
string_without_num = re.sub(r'\d|一|二|三|四|五|六|七|八|九|十', '', string)
|
||||
if string_without_num != string:
|
||||
result.append(string_without_num)
|
||||
string_without_brackets = re.sub(r'\([^()]*\)|\[[^\[\]]*\]|\{[^\{\}]*\}|([^()]*)', "", string_without_num)
|
||||
if string_without_brackets != string_without_num:
|
||||
result.append(string_without_brackets)
|
||||
pure_string = string_without_brackets.split("科")[0] + "科"
|
||||
if pure_string != string_without_brackets:
|
||||
result.append(pure_string)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user