From cb06de0cacc9195a58efc78e4de1834d7ba90b58 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Fri, 1 Dec 2023 22:22:23 +0800 Subject: [PATCH] 0.1.60 --- PyPI/setup.cfg | 2 +- PyPI/src/guan.egg-info/PKG-INFO | 2 +- PyPI/src/guan/data_processing.py | 2 +- PyPI/src/guan/others.py | 73 ++++++++++++++++++++++++-------- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index b5baba6..883b410 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.59 +version = 0.1.60 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 431308b..c205acb 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: guan -Version: 0.1.59 +Version: 0.1.60 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 a9e5d4b..7da9b20 100644 --- a/PyPI/src/guan/data_processing.py +++ b/PyPI/src/guan/data_processing.py @@ -638,7 +638,7 @@ def get_all_filenames_in_directory(directory='./', file_format=None): file_list.append(files[i0]) return file_list -# 读取文件夹中某种文本文件类型的文件路径和内容 +# 读取文件夹中某种文本类型的文件路径和内容 @guan.function_decorator def read_text_files_in_directory(directory='./', file_format='.md'): import os diff --git a/PyPI/src/guan/others.py b/PyPI/src/guan/others.py index 8205711..a0254f9 100644 --- a/PyPI/src/guan/others.py +++ b/PyPI/src/guan/others.py @@ -1,6 +1,61 @@ # Module: others import guan +# 获取CPU使用率 +@guan.function_decorator +def get_cpu_usage(interval=1): + import psutil + cpu_usage = psutil.cpu_percent(interval=interval) + return cpu_usage + +# 获取内存信息 +@guan.function_decorator +def get_memory_info(): + import psutil + memory_info = psutil.virtual_memory() + total_memory = memory_info.total/(1024**2) + used_memory = memory_info.used/(1024**2) + available_memory = memory_info.available/(1024**2) + used_memory_percent = memory_info.percent + return total_memory, used_memory, available_memory, used_memory_percent + +# 将WordPress导出的XML格式文件转换成多个MarkDown格式的文件 +@guan.function_decorator +def convert_wordpress_xml_to_markdown(xml_file='./a.xml', convert_content=1, replace_more=[]): + import xml.etree.ElementTree as ET + import re + tree = ET.parse(xml_file) + root = tree.getroot() + for item in root.findall('.//item'): + print(item) + title = item.find('title').text + content = item.find('.//content:encoded', namespaces={'content': 'http://purl.org/rss/1.0/modules/content/'}).text + if convert_content == 1: + content = re.sub(r'', '', content) + content = content.replace('

', '') + content = content.replace('

', '') + content = content.replace('
    ', '') + content = content.replace('
', '') + content = content.replace('', '') + content = content.replace('', '') + content = content.replace('', '') + content = content.replace('
  • ', '+ ') + content = content.replace('', '') + content = re.sub(r'', '## ', content) + content = re.sub(r'', '### ', content) + content = re.sub(r'', '#### ', content) + for replace_item in replace_more: + content = content.replace(replace_item, '') + for _ in range(100): + content = content.replace('\n\n\n', '\n\n') + else: + pass + markdown_content = f"# {title}\n{content}" + markdown_file_path = f"{title}.md" + cleaned_filename = re.sub(r'[/:*?"<>|\'\\]', ' ', markdown_file_path) + with open(cleaned_filename, 'w', encoding='utf-8') as md_file: + md_file.write(markdown_content) + # 获取运行的日期和时间并写入文件 @guan.function_decorator def statistics_with_day_and_time(content='', filename='a', file_format='.txt'): @@ -34,24 +89,6 @@ def split_text(text, wrap_width=3000): split_text_list = textwrap.wrap(text, wrap_width) return split_text_list -# 获取CPU使用率 -@guan.function_decorator -def get_cpu_usage(interval=1): - import psutil - cpu_usage = psutil.cpu_percent(interval=interval) - return cpu_usage - -# 获取内存信息 -@guan.function_decorator -def get_memory_info(): - import psutil - memory_info = psutil.virtual_memory() - total_memory = memory_info.total/(1024**2) - used_memory = memory_info.used/(1024**2) - available_memory = memory_info.available/(1024**2) - used_memory_percent = memory_info.percent - return total_memory, used_memory, available_memory, used_memory_percent - # 获取本月的所有日期 @guan.function_decorator def get_days_of_the_current_month(str_or_datetime='str'):