Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41fd03e

Browse files
committed
增加函数注释
1 parent53dd2d2 commit41fd03e

File tree

12 files changed

+401
-52
lines changed

12 files changed

+401
-52
lines changed

‎office/api/email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
defsend_email(key,msg_from,msg_to,msg_cc=None,attach_files=[],msg_subject='',content='',host=Mail_Type['qq'],
1010
port=465):
1111
"""
12-
发送邮件函数
12+
自动发送邮件
1313
1414
参数:
1515
key (str): 邮箱账户密钥

‎office/api/excel.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
deffake2excel(columns=['name'],rows=1,path='./fake2excel.xlsx',language='zh_CN'):
88
"""
99
自动创建Excel,并且模拟数据
10+
视频:https://www.bilibili.com/video/BV1wr4y1b7uk/
1011
Args:
1112
columns: 列名。可以模拟的列有:http://python4office.cn/python-office/fake2excel/
1213
rows: 生成多少行数据。默认值:1
@@ -19,37 +20,77 @@ def fake2excel(columns=['name'], rows=1, path='./fake2excel.xlsx', language='zh_
1920
poexcel.fake2excel(columns,rows,path,language)
2021

2122

22-
# 多个excel,合并到一个excel的不同sheet中
2323
defmerge2excel(dir_path,output_file='merge2excel.xlsx'):
2424
"""
25+
多个excel,合并到一个excel的不同sheet中
26+
文档:https://mp.weixin.qq.com/s/3ZhZZfGlpNhszCWnOBeklg
27+
视频:https://www.bilibili.com/video/BV1Th4y1Y7kd/
2528
:param dir_path:
2629
:param output_file:
2730
:return:
2831
"""
2932
poexcel.merge2excel(dir_path,output_file)
3033

3134

32-
# 同一个excel里的不同sheet,拆分为不同的excel文件
35+
#
3336

3437
defsheet2excel(file_path,output_path='./'):
38+
"""
39+
同一个excel里的不同sheet,拆分为不同的excel文件
40+
视频:https://www.bilibili.com/video/BV1714y147Ao/
41+
Args:
42+
file_path:
43+
output_path:
44+
45+
Returns:
46+
47+
"""
3548
poexcel.sheet2excel(file_path,output_path)
3649

3750

3851
defmerge2sheet(dir_path,output_sheet_name:str='Sheet1',output_excel_name:str='merge2sheet'):
52+
"""
53+
实现多个Excel的多个sheet的自动合并
54+
文档:https://mp.weixin.qq.com/s/qQxIsSPHfILTCxZ8PBv6QA
55+
Args:
56+
dir_path:
57+
output_sheet_name:
58+
output_excel_name:
59+
60+
Returns:
61+
62+
"""
3963
poexcel.merge2sheet(dir_path,output_sheet_name,output_excel_name)
4064

4165

42-
# 搜索excel中指定内容的文件、行数、内容详情
4366
# PR内容 & 作者:https://gitee.com/CoderWanFeng/python-office/pulls/10
44-
4567
deffind_excel_data(search_key:str,target_dir:str):
68+
"""
69+
搜索excel中指定内容的文件、行数、内容详情
70+
视频:https://www.bilibili.com/video/BV1Bd4y1B7yr/
71+
Args:
72+
search_key:
73+
target_dir:
74+
75+
Returns:
76+
77+
"""
4678
poexcel.find_excel_data(search_key,target_dir)
4779

4880

49-
# 按指定列的内容,拆分excel
5081
# PR内容 & 作者::https://gitee.com/CoderWanFeng/python-office/pulls/11
5182

5283
defsplit_excel_by_column(filepath:str,column:int,worksheet_name:str=None):
84+
"""
85+
按指定列的内容,拆分excel
86+
Args:
87+
filepath:
88+
column:
89+
worksheet_name:
90+
91+
Returns:
92+
93+
"""
5394
poexcel.split_excel_by_column(filepath,column,worksheet_name)
5495

5596

@@ -63,6 +104,3 @@ def excel2pdf(excel_path, pdf_path, sheet_id: int = 0):
63104
:return: None
64105
"""
65106
poexcel.excel2pdf(excel_path,pdf_path,sheet_id)
66-
67-
# def merge2excel(excel_path, output='merge2excel.xlsx'):
68-
# poexcel.merge2excel(excel_path, output)

‎office/api/file.py

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: UTF-8 -*-
22

33
importpofile
4-
importsearch4file
54

65

76
# todo:输入文件路径
@@ -10,7 +9,7 @@
109
defreplace4filename(path:str,del_content,replace_content='',dir_rename:bool=True,
1110
file_rename:bool=True,suffix=None):
1211
"""
13-
批量修改文件/文件夹名称
12+
批量重命名 1:批量修改文件/文件夹名称
1413
:param path: 必填,需要修改文件夹/文件名称的根目录,注意:该根目录名称不会被修改
1514
:param del_content: 必填,需要替换/删除的内容
1615
:param replace_content: 选填,替换后的内容,不填则实现删除效果
@@ -22,55 +21,115 @@ def replace4filename(path: str, del_content, replace_content='', dir_rename: boo
2221
pofile.replace4filename(path,del_content,replace_content,dir_rename,file_rename,suffix)
2322

2423

25-
#todo:输入文件路径
26-
defsearch_by_content(search_path:str,content:str):
24+
#author:https://github.com/CoderWanFeng/python-office/pull/72
25+
deffile_name_insert_content(file_path:str,insert_position:int,insert_content:str):
2726
"""
28-
通过内容搜索文件
27+
批量重命名 2:在文件名中间插入字符
2928
Args:
30-
search_path: 需要搜索的目录
31-
content: 搜索的内容
29+
file_path:
30+
insert_position:
31+
insert_content:
3232
3333
Returns:
3434
3535
"""
36-
search4file.search_by_content(search_path=search_path,search_content=content)
37-
38-
39-
# author:https://github.com/CoderWanFeng/python-office/pull/72
40-
41-
deffile_name_insert_content(file_path:str,insert_position:int,insert_content:str):
4236
pofile.file_name_insert_content(file_path,insert_position,insert_content)
4337

4438

4539
# author:https://github.com/CoderWanFeng/python-office/pull/72
46-
4740
deffile_name_add_prefix(file_path:str,prefix_content:str):
41+
"""
42+
批量重命名 3:给文件名给增加前缀
43+
Args:
44+
file_path:
45+
prefix_content:
46+
47+
Returns:
48+
49+
"""
4850
pofile.file_name_add_prefix(file_path,prefix_content)
4951

5052

5153
# author:https://github.com/CoderWanFeng/python-office/pull/72
52-
5354
deffile_name_add_postfix(file_path,postfix_content):
54-
pofile.file_name_add_postfix(file_path,postfix_content)
55-
55+
"""
56+
批量重命名 4:给文件名给增加后缀
57+
Args:
58+
file_path:
59+
postfix_content:
5660
57-
# author:https://github.com/CoderWanFeng/python-office/pull/74
61+
Returns:
5862
59-
defsearch_specify_type_file(file_path,file_type):
60-
pofile.search_specify_type_file(file_path,file_type)
63+
"""
64+
pofile.file_name_add_postfix(file_path,postfix_content)
6165

6266

6367
defoutput_file_list_to_excel(dir_path):
68+
"""
69+
整理当前文件夹下的文件名,到一个Excel里
70+
Args:
71+
dir_path:
72+
73+
Returns:
74+
75+
"""
6476
pofile.output_file_list_to_excel(dir_path)
6577

6678

6779
defadd_line_by_type(add_line_dict:dict,file_path,file_type='.py',output_path=r'add_line'):
80+
"""
81+
#TODO:忘记功能了,待测试
82+
Args:
83+
add_line_dict:
84+
file_path:
85+
file_type:
86+
output_path:
87+
88+
Returns:
89+
90+
"""
6891
pofile.add_line_by_type(add_line_dict,file_path,file_type,output_path)
6992

7093

94+
# author:https://github.com/CoderWanFeng/python-office/pull/74
95+
defsearch_specify_type_file(file_path,file_type):
96+
"""
97+
当前路径下,搜索指定类型的文件
98+
Args:
99+
file_path:
100+
file_type:
101+
102+
Returns:
103+
104+
"""
105+
pofile.search_specify_type_file(file_path,file_type)
106+
107+
71108
defgroup_by_name(path,output_path=None,del_old_file=None):
109+
"""
110+
#TODO:忘记功能了,待测试
111+
Args:
112+
path:
113+
output_path:
114+
del_old_file:
115+
116+
Returns:
117+
118+
"""
72119
pofile.group_by_name(path,output_path,del_old_file)
73120

74121

75122
defget_files(path:str,name:str='',suffix:str=None,sub:bool=False,level:int=0)->list:
123+
"""
124+
搜索当前路径下,所有指定类型的文件,并以列表的形式返回
125+
Args:
126+
path:
127+
name:
128+
suffix:
129+
sub:
130+
level:
131+
132+
Returns:
133+
134+
"""
76135
returnpofile.get_files(path,name,suffix,sub,level)

‎office/api/image.py

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,32 @@
33

44

55
defcompress_image(input_file:str,output_file:str,quality:int):
6+
"""
7+
压缩图像文件,以减小其文件大小,同时尽量保持视觉质量。
8+
9+
参数:
10+
input_file (str): 需要压缩的输入图像文件的路径。
11+
output_file (str): 压缩后的图像文件保存路径。
12+
quality (int): 压缩质量等级,取值范围为 0 到 95。数值越高,表示图像质量越好,但文件体积也越大。
13+
14+
返回值:
15+
None
16+
"""
17+
618
poimage.compress_image(input_file,output_file,quality)
719

820

921
defimage2gif():
22+
"""
23+
将图像转换为 GIF 格式。
24+
25+
本函数通过调用 poimage 模块的 image2gif 方法来实现图像到 GIF 格式的转换。
26+
该方法负责处理图像数据,将其编码为 GIF 格式,并保存或输出转换后的 GIF 文件。
27+
"""
1028
poimage.image2gif()
1129

1230

31+
1332
# todo:输出文件路径
1433

1534
defadd_watermark(file,mark,output_path='./',color="#eaeaea",size=30,opacity=0.35,space=200,
@@ -35,24 +54,80 @@ def add_watermark(file, mark, output_path='./', color="#eaeaea", size=30, opacit
3554

3655
# todo:输入文件路径
3756

38-
defimg2Cartoon(path,client_api='OVALewIvPyLmiNITnceIhrYf',client_secret='rpBQH8WuXP4ldRQo5tbDkv3t0VgzwvCN'):
57+
defimg2Cartoon(path,client_api='',client_secret=''):
58+
"""
59+
将图片转换为卡通风格。
60+
61+
本函数通过调用百度的API,将给定路径下的图片转换成卡通风格的图片。客户端的API密钥和密钥秘密用于认证。
62+
63+
参数:
64+
- path (str): 图片文件的路径。
65+
- client_api (str): 客户端的API密钥,默认值为'OVALewIvPyLmiNITnceIhrYf'。
66+
- client_secret (str): 客户端的密钥秘密,默认值为'rpBQH8WuXP4ldRQo5tbDkv3t0VgzwvCN'。
67+
68+
返回:
69+
无直接返回值,但会生成或显示转换后的卡通风格图片。
70+
"""
71+
# 调用img2Cartoon函数处理图片,参数包括图片路径、API密钥和密钥秘密
3972
poimage.img2Cartoon(path,client_api,client_secret)
40-
# mainImage.img2Cartoon(path, client_api, client_secret)
73+
4174

4275

4376
defdown4img(url,output_path='.',output_name='down4img',type='jpg'):
77+
"""
78+
下载图片并保存到指定路径。
79+
80+
调用此函数以从给定的URL下载图片,并将其保存在指定的输出路径中。如果没有指定输出路径和名称,将使用默认值。
81+
82+
参数:
83+
- url (str): 图片的URL地址。
84+
- output_path (str, optional): 保存图片的路径,默认为当前目录('.')。
85+
- output_name (str, optional): 保存图片时使用的文件名,默认为'output_name'。
86+
- type (str, optional): 图片的文件类型,默认为'jpg'。
87+
88+
返回:
89+
无返回值。图片将直接保存到指定的路径中。
90+
"""
91+
# 调用poimage模块中的down4img函数执行图片下载和保存操作
4492
poimage.down4img(url,output_path,output_name,type)
45-
# mainImage.down4img(url, output_name, type)
4693

4794

4895
deftxt2wordcloud(filename,color="white",result_file="your_wordcloud.png"):
96+
"""
97+
根据指定的文本文件生成词云图像。
98+
99+
参数:
100+
filename (str): 文本文件的路径。
101+
color (str, optional): 词云的背景颜色。默认为 "white"。
102+
result_file (str, optional): 生成的词云图像文件名。默认为 "your_wordcloud.png"。
103+
104+
返回:
105+
无返回值,但会生成一个词云图像文件。
106+
"""
107+
# 调用poimage模块的txt2wordcloud方法生成词云
49108
poimage.txt2wordcloud(filename,color,result_file)
50109

51110

111+
52112
defpencil4img(input_img,output_path='./',output_name='pencil4img.jpg'):
113+
"""
114+
使用pencil4img算法处理图像。
115+
116+
该函数接受一个输入图像,并将其转换为铅笔画风格的图像。转换后的图像将保存在指定的输出路径下,文件名为output_name。
117+
118+
参数:
119+
- input_img: 输入的图像文件路径。必须是一个字符串,表示图像文件的路径。
120+
- output_path: 输出图像的路径。这是一个可选参数,默认值为当前目录('./')。
121+
- output_name: 转换后的图像文件名。这是一个可选参数,默认值为'pencil4img.jpg'。
122+
123+
返回值:
124+
无返回值。函数将处理后的图像保存在指定路径下。
125+
"""
126+
# 调用poimage库中的pencil4img函数处理图像
53127
poimage.pencil4img(input_img,output_path,output_name)
54128

55129

130+
56131
defdecode_qrcode(qrcode_path):
57132
"""
58133
解析二维码
@@ -63,4 +138,16 @@ def decode_qrcode(qrcode_path):
63138

64139

65140
defdel_watermark(input_image,output_image=r'./del_water_mark.jpg'):
141+
"""
142+
从输入的图片中删除水印,并保存处理后的图片到指定路径。
143+
144+
参数:
145+
input_image (str): 输入图片的路径,这是需要进行水印删除处理的图片。
146+
output_image (str, optional): 处理后图片的保存路径。默认为当前目录下的'del_water_mark.jpg'。
147+
148+
返回:
149+
无返回值。该函数直接将处理后的图片文件保存到指定路径。
150+
"""
151+
# 调用poimage库中的del_watermark函数来删除图片中的水印
66152
poimage.del_watermark(input_image,output_image)
153+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp