From 14c6136567a0fc53821ec42ad3be64662d89b271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80=C3=AE=C3=97=C3=9A=C3=95=C3=B1?= Date: Sun, 9 Oct 2022 15:14:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8E=86=E8=A7=A3=E6=9E=90=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/re_to_jianli.py | 118 ++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 39 deletions(-) diff --git a/utils/re_to_jianli.py b/utils/re_to_jianli.py index 0022e4e..5715ba3 100644 --- a/utils/re_to_jianli.py +++ b/utils/re_to_jianli.py @@ -617,42 +617,76 @@ def fmt_txt(chk_str): index2 = -1 name2 = '' new_str_list1 = [] - for index, i in enumerate(project_list): - if index <= index2: - continue - if not i: - continue - if i.strip() in ['-', '–', '―', '—']: - index2 = index + 2 - if not name2: - name3 = project_list[index + 2].split('\n')[-1] - new_str = project_list[index - 2] + project_list[index - 1] + i + project_list[ - index + 1] + \ - project_list[index + 2].split(name3)[0] - name2 = name3 - else: - name3 = project_list[index + 2].split('\n')[-1] - if name2: - new_str = name2 + project_list[index - 1] + i + project_list[index + 1] + \ - project_list[index + 2].split(name3)[0] + if '-至今' in project_undergo2: + for index, i in enumerate(project_list): + if index <= index2: + continue + if not i: + continue + if i.strip().startswith('-'): + if i.strip() == '-': + index2 = index + 2 + name3 = project_list[index + 2].split('\n')[-1] + if not name2: + new_str = project_list[index - 2] + project_list[index - 1] + i + project_list[ + index + 1] + \ + project_list[index + 2].split(name3)[0] + name2 = name3 + else: + new_str = name2 + project_list[index - 1] + i + project_list[index + 1] + \ + project_list[index + 2] + name2 = name3 + new_str_list1.append(new_str) else: - new_str = name2 + project_list[index - 1] + i + project_list[index + 1] + \ - project_list[index + 2] - name2 = name3 - new_str_list1.append(new_str) - continue - if i.strip() not in ['-', '–', '―', '—'] and ('-' in i or '–' in i or '―' in i or '—' in i): - index2 = index - if not name2: - name3 = i.split('\n')[-1] - new_str = str_2[index - 2] + str_2[index - 1] + i.split(name3)[0] - name2 = name3 - else: - name3 = i.split('\n')[-1] - new_str = str_2[index - 2] + str_2[index - 1] + i.split(name3)[0] - name2 = name3 - new_str_list1.append(new_str) - continue + name3 = i.split('\n')[-1] + if not name2: + index2 = index + new_str = project_list[index - 2] + project_list[index - 1] + i.split(name3)[0] + name2 = name3 + else: + new_str = name2 + project_list[index - 1] + i.split(name3)[0] + name2 = name3 + new_str_list1.append(new_str) + else: + for index, i in enumerate(project_list): + if index <= index2: + continue + if not i: + continue + if i.strip() in ['-', '–', '―', '—']: + index2 = index + 2 + if not name2: + name3 = project_list[index + 2].split('\n')[-1] + new_str = project_list[index - 2] + project_list[index - 1] + i + project_list[ + index + 1] + \ + project_list[index + 2].split(name3)[0] + name2 = name3 + else: + name3 = project_list[index + 2].split('\n')[-1] + if name2: + new_str = name2 + project_list[index - 1] + i + project_list[index + 1] + \ + project_list[index + 2].split(name3)[0] + else: + new_str = name2 + project_list[index - 1] + i + project_list[index + 1] + \ + project_list[index + 2] + name2 = name3 + new_str_list1.append(new_str) + continue + if i.strip() not in ['-', '–', '―', '—'] and ('-' in i or '–' in i or '―' in i or '—' in i): + index2 = index + if not name2: + name3 = i.split('\n')[-1] + new_str = str_2[index - 2] + str_2[index - 1] + i.split(name3)[0] + name2 = name3 + else: + name3 = i.split('\n')[-1] + if (index - 1) >= len(str_2): + new_str = str_2[index - 2] + i.split(name3)[0] + else: + new_str = str_2[index - 2] + str_2[index - 1] + i.split(name3)[0] + name2 = name3 + new_str_list1.append(new_str) + continue if new_str_list1: for project_str in new_str_list1: project_name_time_str = project_str.split('\n')[0] @@ -675,9 +709,13 @@ def fmt_txt(chk_str): dict_project['work'] = project_name_time_str2[index + 1].split(' ')[-1] break else: - dict_project['time'] = ( - p_str + project_name_time_str2[index + 1] + project_name_time_str2[ - index + 2]).replace('.', '/') + if index + 2 >= len(project_name_time_str2): + dict_project['time'] = ( + p_str + project_name_time_str2[index + 1]).replace('.', '/') + else: + dict_project['time'] = (p_str + project_name_time_str2[index + 1] + + project_name_time_str2[index + 2]).replace('.', + '/') dict_project['name'] = project_name_time_str2[index - 1] if index + 3 <= len(project_name_time_str2): dict_project['work'] = project_name_time_str2[index + 3] @@ -835,6 +873,8 @@ def fmt_txt(chk_str): name1 = str_2[index + 2].strip().strip('\n').split('\n')[-1] if str_2[index + 2].strip().endswith(':') or str_2[index + 2].strip().endswith(':'): name1 = str_2[index + 2].split('\n')[-2] + if not name1: + name1 = str_2[index + 2].split(' ')[0] new_str = str_2[index - 2] + str_2[index - 1] + i + str_2[index + 1] + \ str_2[index + 2].split(name1)[0] name = name1 @@ -2508,4 +2548,4 @@ egreat,海尔,MeleA20,MeleA31,LG1154,极米,杰科,亿典等机顶 """ - fmt_txt(chk_str3) + fmt_txt(chk_str12)