diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 9567d60..f8916ae 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.199 +version = 0.1.200 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO index c3f6edc..a3ec3d2 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: guan -Version: 0.1.199 +Version: 0.1.200 Summary: An open source python package Home-page: https://py.guanjihuan.com Author: guanjihuan diff --git a/PyPI/src/guan/data_processing.py b/PyPI/src/guan/data_processing.py index 2f9199f..8b22517 100644 --- a/PyPI/src/guan/data_processing.py +++ b/PyPI/src/guan/data_processing.py @@ -11,6 +11,16 @@ def logging_with_day_and_time(content='', filename='time_logging', file_format=' else: f2.write(datetime_today+' '+datetime_time+' '+str(content)+'\n') +# 获取当前位置的 Unix 时间戳,并打印某段程序的运行时间 +def record_time_and_print_running_time(start_time=None): + import time + current_time = time.time() + if start_time == None: + print("\n--- 开始计时(第一个记录点)---\n") + else: + print(f"\n--- 自上一个记录点已运行: {current_time - start_time:.2f} 秒 ---\n") + return current_time + # 使用该函数运行某个函数并获取函数计算时间(秒) def timer(function_name, *args, **kwargs): import time diff --git a/PyPI/src/guan/others.py b/PyPI/src/guan/others.py index 17ac539..f652d4f 100644 --- a/PyPI/src/guan/others.py +++ b/PyPI/src/guan/others.py @@ -126,6 +126,29 @@ def get_links_from_pdf(pdf_path, link_starting_form=''): old = u['/A']['/URI'] return links +# 将某个文件夹中的某个类型的文本文件全部修改为另外一个编码,其他文件不变 +def convert_file_encoding_for_one_directory(source_directory, target_directory, file_formats=['.m'], src_encoding='utf-8', dst_encoding='gb18030'): + import os + import shutil + os.makedirs(target_directory, exist_ok=True) + for root, dirs, files in os.walk(source_directory): + rel_path = os.path.relpath(root, source_directory) + target_subdir = os.path.join(target_directory, rel_path) if rel_path != '.' else target_directory + os.makedirs(target_subdir, exist_ok=True) + for file in files: + src_file = os.path.join(root, file) + dst_file = os.path.join(target_subdir, file) + if any(file.lower().endswith(ext.lower()) for ext in file_formats): + try: + with open(src_file, 'r', encoding=src_encoding) as f: + content = f.read() + with open(dst_file, 'w', encoding=dst_encoding) as f: + f.write(content) + except Exception as e: + shutil.copy2(src_file, dst_file) + else: + shutil.copy2(src_file, dst_file) + # 获取当前日期字符串 def get_date(bar=True): import datetime