├── .gitignore
├── LICENSE.txt
├── MANIFEST.in
├── README.md
├── humo_utils
├── __init__.py
├── analytic
│ └── __init__.py
├── conversion
│ ├── __init__.py
│ ├── excel
│ │ └── __init__.py
│ └── pdf
│ │ └── __init__.py
├── datetime_utils
│ └── __init__.py
├── down_file
│ └── __init__.py
├── generates
│ ├── __init__.py
│ ├── address.py
│ ├── area_data.py
│ ├── card_no.py
│ ├── mobile.py
│ └── name.py
└── zip
│ └── __init__.py
├── main.py
├── requirements.txt
├── setup.cfg
├── setup.py
└── tea.yaml
/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mini-Right/HumoUtils/808945e4a34d181fcafeebfbba3c98d3e6388c08/.gitignore
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 | Copyright (c) 2022 Mini-Right
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 | The above copyright notice and this permission notice shall be included in all
10 | copies or substantial portions of the Software.
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 | SOFTWARE.
18 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include requirements.txt
2 | include README.md
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 数据提取
2 | ```python
3 |
4 | from humo_utils import analytic
5 |
6 | if __name__ == '__main__':
7 | data_json = {
8 | "id": "3f2f22e6aad9433aa706a3a187e1dfa6",
9 | "create_time": "2022-04-20 22:53:51",
10 | "update_time": "2022-04-24 18:00:07",
11 | "username": "mini_right",
12 | "nickname": "小右",
13 | "mobile": "13800000000",
14 | "email": "www@anyu.wang",
15 | "status": 1
16 | }
17 | data_xml = """
18 |
19 | 3f2f22e6aad9433aa706a3a187e1dfa6
20 | 2022-04-20 22:53:51
21 | 2022-04-24 18:00:07
22 | mini_right
23 | 小右
24 | 13800000000
25 | www@anyu.wang
26 | 1
27 |
28 | """
29 |
30 | print(analytic(data_json, 'nickname'))
31 | print(analytic(data_xml, 'nickname'))
32 |
33 | ```
34 |
35 | ## 数据转换
36 |
37 | ### Excel
38 |
39 | ```python
40 |
41 | from humo_utils import ToExcel
42 |
43 | if __name__ == '__main__':
44 | excel_path = '/Users/mini-right/Desktop/test.xls'
45 | data = [
46 | {
47 | "id": "3f2f22e6aad9433aa706a3a187e1dfa6",
48 | "create_time": "2022-04-20 22:53:51",
49 | "update_time": "2022-04-24 18:00:07",
50 | "username": "mini_right",
51 | "nickname": "小右",
52 | "mobile": "13800000000",
53 | "email": "www@anyu.wang",
54 | "status": 1
55 | }
56 | ]
57 |
58 | excel = ToExcel(excel_path)
59 | excel.sheet(
60 | title=list(data[0].keys()),
61 | table_data=data,
62 | sheet_name='第一个sheet页'
63 | )
64 | excel.close()
65 | ```
66 |
67 | ### PDF转图片
68 | ```python
69 | from humo_utils import pdf2img
70 |
71 | if __name__ == '__main__':
72 | pdf2img(
73 | pdf_path='/Users/mini-right/Documents/第一个PDF.PDF',
74 | save_path='/Users/mini-right/Documents',
75 | img_name='第一个PDF',
76 | page_list=[1, 3]
77 | )
78 | ```
79 |
80 | ## 日期处理
81 | ```python
82 |
83 | from humo_utils import (get_current_millisecond_time,
84 | get_current_second_time,
85 | get_current_date,
86 | get_current_time,
87 | get_current_datetime,
88 | get_current_week_day,
89 | get_last_week_start_date,
90 | get_last_week_end_date,
91 | get_birthday_date,
92 | get_any_datetime,
93 | get_last_any_day,
94 | cal_date)
95 |
96 | if __name__ == '__main__':
97 | # 获取当前时间戳-毫秒级
98 | print(get_current_millisecond_time())
99 |
100 | # 获取当前时间戳 - 秒级
101 | print(get_current_second_time())
102 |
103 | # 获取当前日期
104 | print(get_current_date())
105 |
106 | # 获取当前时间
107 | print(get_current_time())
108 |
109 | # 获取当前日期时间
110 | print(get_current_datetime())
111 |
112 | # 获取当前是周几
113 | print(get_current_week_day())
114 |
115 | # 获取上周一日期
116 | print(get_last_week_start_date())
117 |
118 | # 获取上周末日期
119 | print(get_last_week_end_date())
120 |
121 | # 根据年龄获取出生日期
122 | # 支持年龄类型: 18Y 18Y-1D 18Y+1M
123 | # Y年 M月 D日
124 | # 以date_time参数为基准进行计算
125 | print(get_birthday_date('1Y-1D', '2020-01-01'))
126 |
127 | # 获取距离传入日期的任意偏移时间的日期时间
128 | # 默认为当前日期时间 格式为YYYY-MM-DD HH:mm:ss (date_time要与format格式相同)
129 | print(get_any_datetime(
130 | date_time='2022-01-01 00:00:00',
131 | year=1
132 | ))
133 | print(get_any_datetime(
134 | date_time='2022-01-01',
135 | year=1,
136 | format='YYYY-MM-DD'
137 | ))
138 |
139 | # 获取最近日期
140 | print(get_last_any_day())
141 |
142 | # 计算日期差
143 | # 以date2为基准计算与date1的时间差
144 | print(cal_date('2022-01-02', '2022-01-01'))
145 |
146 | ```
147 |
148 | ## 文件下载
149 | ```python
150 | from humo_utils import Down
151 |
152 | if __name__ == '__main__':
153 | Down.main(
154 | url='https://cdn.nlark.com/yuque/0/2021/jpeg/anonymous/1637675879100-f1281f5d-060a-48ce-b674-3245e4ea093e.jpeg?x-oss-process=image%2Fresize%2Cm_fill%2Cw_320%2Ch_320%2Fformat%2Cpng',
155 | local_path='/Users/mini-right/Desktop/poloyy.png',
156 | refresh=True,
157 | progress=True
158 | )
159 |
160 | ```
161 |
162 | ## 生成器
163 |
164 | ```python
165 |
166 | from humo_utils import generate_card, generate_name, generate_mobile, generate_address, generate_identity_info
167 |
168 | if __name__ == '__main__':
169 | # 生成指定出生日期身份证号
170 | print(generate_card(
171 | birthday='2000-01-01',
172 | sex='1'
173 | ))
174 | # 生成指定年龄身份证号
175 | print(generate_card(
176 | age='18Y',
177 | sex='2',
178 | address='110101'
179 | ))
180 |
181 | # 生成姓名
182 | print(generate_name())
183 |
184 | # 生成手机号
185 | print(generate_mobile())
186 |
187 | # 生成地址
188 | print(generate_address(address_no='110101'))
189 |
190 | # 生成完整身份信息
191 | print(generate_identity_info(age='10Y', sex='2'))
192 |
193 | ```
194 |
195 | ## 文件夹压缩
196 | ```python
197 | from humo_utils import write_all_file_to_zip
198 |
199 | if __name__ == '__main__':
200 | write_all_file_to_zip(
201 | dir_path='/Users/mini-right/Desktop/未命名文件夹',
202 | zip_path='/Users/mini-right/Desktop/未命名文件夹.zip'
203 | )
204 | ```
--------------------------------------------------------------------------------
/humo_utils/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2022/7/4 11:31
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : __init__.py.py
7 | # @Software : PyCharm
8 | # @Description :
9 | from humo_utils.analytic import analytic
10 | from humo_utils.conversion.excel import ToExcel
11 | from humo_utils.conversion.pdf import pdf2img
12 | from humo_utils.datetime_utils import *
13 | from humo_utils.down_file import Down
14 | from humo_utils.generates import *
15 | from humo_utils.zip import write_all_file_to_zip
16 |
17 | __all__ = [
18 | 'analytic',
19 | 'ToExcel',
20 | 'pdf2img',
21 | 'get_current_millisecond_time',
22 | 'get_current_second_time',
23 | 'get_current_date',
24 | 'get_current_time',
25 | 'get_current_datetime',
26 | 'get_current_week_day',
27 | 'get_last_week_start_date',
28 | 'get_last_week_end_date',
29 | 'get_birthday_date',
30 | 'get_any_datetime',
31 | 'get_last_any_day',
32 | 'cal_date',
33 | 'Down',
34 | 'generate_card',
35 | 'generate_name',
36 | 'generate_mobile',
37 | 'generate_address',
38 | 'generate_identity_info',
39 | 'write_all_file_to_zip',
40 | ]
41 |
--------------------------------------------------------------------------------
/humo_utils/analytic/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/7/8 18:54
3 | # @Author : Mini-Right
4 | # @Email : www@anyu.wang
5 | # @File : analyticBody.py
6 | # @Software: PyCharm
7 |
8 | """解析响应报文"""
9 |
10 | import ast
11 |
12 |
13 | def analytic(body, key: str):
14 | """
15 | 根据传入的key获取报文中对应的value,支持xml、json
16 | """
17 | if not isinstance(body, dict):
18 | try:
19 | body = ast.literal_eval(body)
20 | except:
21 | body = XmlToDict().main(body)
22 |
23 | value = get_json_value_by_key(in_json=body, target_key=key, results=[])
24 |
25 | if len(value) == 0:
26 | return ''
27 | else:
28 | return value[-1]
29 |
30 |
31 | def get_json_value_by_key(in_json, target_key, results=[]) -> list:
32 | if isinstance(in_json, dict): # 如果输入数据的格式为dict
33 | for key in in_json.keys(): # 循环获取key
34 | data = in_json[key]
35 | get_json_value_by_key(data, target_key, results=results) # 回归当前key对于的value
36 | if key == target_key: # 如果当前key与目标key相同就将当前key的value添加到输出列表
37 | results.append(data)
38 |
39 | elif isinstance(in_json, list) or isinstance(in_json, tuple): # 如果输入数据格式为list或者tuple
40 | for data in in_json: # 循环当前列表
41 | get_json_value_by_key(data, target_key, results=results) # 回归列表的当前的元素
42 |
43 | return results
44 |
45 |
46 | import xml.etree.ElementTree as ET
47 |
48 |
49 | class XmlToDict(object):
50 |
51 | def main(self, xml):
52 | xml = ET.XML(xml)
53 | dict = self.set_xml_dict(xml)
54 | return dict
55 |
56 | def set_xml_dict(self, root):
57 | t_dict = {}
58 | for sub_root in list(root):
59 | self.xml_dict = {root.tag: ''}
60 | if len(list(sub_root)) <= 0:
61 | t_dict.update({sub_root.tag: sub_root.text})
62 | else:
63 | re_t_dict = self.recursive_xml(sub_root)
64 | t_dict.update({sub_root.tag: re_t_dict})
65 | return {root.tag: t_dict}
66 |
67 | def recursive_xml(self, root):
68 | t_dict = {}
69 | # 处理层级
70 | for sub_root in list(root):
71 | if len(list(sub_root)) > 0:
72 | re_t_dict = self.recursive_xml(sub_root)
73 | t_dict.update({sub_root.tag: re_t_dict})
74 | continue
75 |
76 | t_dict.update({sub_root.tag: sub_root.text})
77 | return t_dict
78 |
--------------------------------------------------------------------------------
/humo_utils/conversion/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2022/4/29 21:00
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : __init__.py.py
7 | # @Software : PyCharm
8 | # @Description :
9 |
--------------------------------------------------------------------------------
/humo_utils/conversion/excel/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2022/6/28 21:45
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : excel.py
7 | # @Software : PyCharm
8 | # @Description :
9 | from typing import List
10 |
11 | import xlsxwriter
12 |
13 |
14 | class ToExcel(object):
15 | def __init__(self, excel_path: str):
16 | self.f = xlsxwriter.Workbook(excel_path,
17 | options={
18 | 'strings_to_urls': False,
19 | 'default_date_format': '%Y-%m-%d %H:%M:%S'
20 | })
21 |
22 | def sheet(self, title: list, table_data: List[dict], sheet_name: str = 'sheet', sheet_format: list = []):
23 | ws = self.f.add_worksheet(sheet_name)
24 | for _ in sheet_format:
25 | ws.set_column(*_)
26 | count = 0
27 | for i in range(len(title)):
28 | ws.write(count, i, title[i])
29 | count += 1
30 | # 写入excel数据
31 | for data in table_data:
32 | self.__write(ws, title, count, data)
33 | count += 1
34 |
35 | def close(self):
36 | self.f.close()
37 |
38 | def __write(self, ws, title, count, data):
39 | num = 0
40 | for _title in title:
41 | ws.write_string(count, num,
42 | str(data[_title]) if data[_title] else '')
43 | num += 1
44 |
--------------------------------------------------------------------------------
/humo_utils/conversion/pdf/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2022/3/31 16:42
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : pdf2img.py
7 | # @Software : PyCharm
8 | # @Description :
9 | from typing import List
10 |
11 | import fitz # pymupdf
12 | from loguru import logger
13 |
14 |
15 |
16 |
17 | def pdf2img(pdf_path: str, save_path: str, img_name: str, page_list: List[int] = None):
18 | """
19 | PDF转PNG图片
20 | pdf2img(
21 | '/Users/mini-right/Documents/firefly/eff/humoBackEnd/files/4529ec62a3aa4a6cbda15a0dfeb34870/第一个PDF.PDF',
22 | '/Users/mini-right/Documents/firefly/eff/humoBackEnd/files/4529ec62a3aa4a6cbda15a0dfeb34870',
23 | '第一个PDF',
24 | [1, 3]
25 | )
26 | :param pdf_path: PDF本地路径
27 | :param save_path: PDF转图片保存的路径 不带后面的/
28 | :param img_name: 图片名称 不带后缀
29 | :param page_list: 打印页码 从1开始 为空则全部打印
30 | :return:
31 | """
32 | logger.debug(f"PDF转图片 pdf_path: {pdf_path} save_path: {save_path} img_name: {img_name} page_list: {page_list}")
33 | doc = fitz.open(pdf_path)
34 | for pg in range(doc.pageCount):
35 | this_page = pg + 1
36 | logger.debug(f'{img_name}开始生成第{this_page}张图片')
37 | # 跳过不转换的页面
38 | if page_list and this_page not in page_list:
39 | # logger.debug(f'{img_name}开始生成第{this_page}张图片 -- 跳过')
40 | continue
41 | page = doc[pg]
42 | rotate = int(0)
43 | # 每个尺寸的缩放系数为8,这将为我们生成分辨率提高64倍的图像。
44 | zoom_x = zoom_y = 8.0
45 | trans = fitz.Matrix(zoom_x, zoom_y).prerotate(rotate)
46 | pm = page.get_pixmap(matrix=trans, alpha=False)
47 | png_path = f"{save_path}/{img_name}-{this_page}.PNG"
48 | pm.save(png_path)
49 | logger.debug(f'转换图片成功: {png_path}')
50 |
--------------------------------------------------------------------------------
/humo_utils/datetime_utils/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2022/4/29 18:07
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : __init__.py.py
7 | # @Software : PyCharm
8 | # @Description :
9 | import datetime
10 | import time
11 | from typing import Dict, Optional
12 |
13 | import arrow
14 |
15 |
16 | def get_current_millisecond_time() -> int:
17 | """
18 | description: 获取当前时间戳-毫秒级
19 | :return: 1599805496610 -> str
20 | """
21 | return int(arrow.now().timestamp() * 1000)
22 |
23 |
24 | def get_current_second_time() -> int:
25 | """
26 | description: 获取当前时间戳-秒级
27 | :return:
28 | """
29 | return int(arrow.now().timestamp())
30 |
31 |
32 | def get_current_date() -> str:
33 | """
34 | description: 获取当前日期
35 | :return: 2021-02-19 -> str
36 | """
37 | return arrow.now().format('YYYY-MM-DD')
38 |
39 |
40 | def get_current_time():
41 | """
42 | description: 获取当前时间
43 | :return: 14:41:15 -> str
44 | """
45 | return arrow.now().format('HH:mm:ss')
46 |
47 |
48 | def get_current_datetime():
49 | """
50 | description: 获取当前日期时间
51 | :return: 2021-02-19 14:41:15 -> str
52 | """
53 | return arrow.now().format('YYYY-MM-DD HH:mm:ss')
54 |
55 |
56 | def get_current_week_day() -> str:
57 | """
58 | description: 获取当前是周几
59 | :return:
60 | """
61 | return int(arrow.now().weekday()) + 1
62 |
63 |
64 | def get_last_week_start_date() -> str:
65 | """
66 | description: 获取上周一日期
67 | :return:
68 | """
69 | return arrow.now().shift(weeks=-1, days=-get_current_week_day() + 1).format('YYYY-MM-DD')
70 |
71 |
72 | def get_last_week_end_date() -> str:
73 | """
74 | description: 获取上周末日期
75 | :return:
76 | """
77 | return arrow.now().shift(weeks=-1, days=-get_current_week_day() + 1 + 6).format('YYYY-MM-DD')
78 |
79 |
80 | def get_birthday_date(age: str, date_time: str = get_current_date()):
81 | """
82 | description: 根据年龄获取出生日期
83 | 支持年龄类型: 18Y 18Y-1D 18Y+1M
84 | :param date_time: 日期
85 | :param age: 年龄
86 | :return:
87 | """
88 | age = str(age)
89 | if 'Y' not in age and 'M' not in age and 'D' not in age:
90 | age = f"{age}Y"
91 | shift_dict = conduct_add_subtract_shift(age)
92 | # 年龄倒计算 shift取反
93 | shift = {k: -v for k, v in shift_dict.items()}
94 | birthday = get_any_datetime(date_time=date_time,
95 | format="YYYY-MM-DD",
96 | **shift).split(" ")[0]
97 | return birthday
98 |
99 |
100 | def get_any_datetime(
101 | date_time: Optional[str] = get_current_datetime(),
102 | year: Optional[int] = 0,
103 | month: Optional[int] = 0,
104 | day: Optional[int] = 0,
105 | hour: Optional[int] = 0,
106 | minute: Optional[int] = 0,
107 | second: Optional[int] = 0,
108 | format: str = "YYYY-MM-DD HH:mm:ss",
109 | ) -> str:
110 | """
111 | description: 获取距离传入日期的任意偏移时间的日期时间
112 | :param date_time: 时间
113 | :param year: 年 1代表传入时间+1年 -1代表当前时间-1年 默认=0
114 | :param month: 月 1代表传入时间+1月 -1代表当前时间-1月 默认=0
115 | :param day: 日 1代表传入时间+1日 -1代表当前时间-1日 默认=0
116 | :param hour: 时 1代表传入时间+1时 -1代表当前时间-1时 默认=0
117 | :param minute: 分 1代表传入时间+1分 -1代表当前时间-1分 默认=0
118 | :param second: 秒 1代表传入时间+1秒 -1代表当前时间-1秒 默认=0
119 | :param format: 格式
120 | :return: 2020-09-11 14:21:36 -> str
121 | """
122 | return (arrow.get(date_time, format).shift(
123 | years=year,
124 | months=month,
125 | days=day,
126 | hours=hour,
127 | minutes=minute,
128 | seconds=second,
129 | ).format(format))
130 |
131 |
132 | def conduct_shift(shift: str):
133 | year = 0
134 | month = 0
135 | day = 0
136 | hour = 0
137 | minute = 0
138 | second = 0
139 | shift_list = ["Y", "M", "D", "H", "m", "s"]
140 | # 不包含shift中字符 默认为日
141 | if shift[-1] not in shift_list:
142 | day = int(shift)
143 | else:
144 | if shift[-1] == "Y":
145 | year = int(shift[:-1])
146 | if shift[-1] == "M":
147 | month = int(shift[:-1])
148 | if shift[-1] == "D":
149 | day = int(shift[:-1])
150 | if shift[-1] == "H":
151 | hour = int(shift[:-1])
152 | if shift[-1] == "m":
153 | minute = int(shift[:-1])
154 | if shift[-1] == "s":
155 | second = int(shift[:-1])
156 |
157 | return {
158 | "year": year,
159 | "month": month,
160 | "day": day,
161 | "hour": hour,
162 | "minute": minute,
163 | "second": second,
164 | }
165 |
166 |
167 | def conduct_add_subtract_shift(shifts):
168 | shift = {
169 | "year": 0,
170 | "month": 0,
171 | "day": 0,
172 | "hour": 0,
173 | "minute": 0,
174 | "second": 0
175 | }
176 | if "+" in shifts or "-" in shifts:
177 | begin = shifts.split("+")[0] if "+" in shifts else shifts.split("-")[0]
178 | end = shifts.replace(begin, "", 1)
179 | begin_shift: Dict[str, int] = conduct_shift(begin)
180 | end_shift: Dict[str, int] = conduct_shift(end)
181 | shift["year"] = begin_shift.get("year") + end_shift.get("year")
182 | shift["month"] = begin_shift.get("month") + end_shift.get("month")
183 | shift["day"] = begin_shift.get("day") + end_shift.get("day")
184 | shift["hour"] = begin_shift.get("hour") + end_shift.get("hour")
185 | shift["minute"] = begin_shift.get("minute") + end_shift.get("minute")
186 | shift["second"] = begin_shift.get("second") + end_shift.get("second")
187 | else:
188 | shift = conduct_shift(shifts)
189 | return shift
190 |
191 |
192 | def get_last_any_day(last_day: int = 1):
193 | return get_any_datetime(date_time=get_current_date(),
194 | day=-last_day,
195 | format="YYYY-MM-DD")
196 |
197 |
198 | def cal_date(date1, date2):
199 | """
200 | 计算日期差
201 | :param date1: 开始日期
202 | :param date2: 结束日期
203 | """
204 | date1 = time.strptime(date1, "%Y-%m-%d")
205 | date2 = time.strptime(date2, "%Y-%m-%d")
206 | date1 = datetime.datetime(date1[0], date1[1], date1[2])
207 | date2 = datetime.datetime(date2[0], date2[1], date2[2])
208 | cal = date2 - date1
209 | return cal.days
210 |
211 |
--------------------------------------------------------------------------------
/humo_utils/down_file/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2022/4/29 20:58
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : __init__.py.py
7 | # @Software : PyCharm
8 | # @Description :
9 | import os
10 |
11 | import requests as requests
12 | from tqdm import tqdm
13 | from loguru import logger
14 |
15 |
16 | class Down(object):
17 |
18 | @classmethod
19 | def main(cls, url: str, local_path: str, refresh: bool = False, progress: bool = False):
20 | """
21 | :param url: 目标url地址
22 | :param local_path: 保存本地路径
23 | :param refresh: 当本地文件已存在 是否刷新
24 | :param progress: 是否展示进度条
25 | :return:
26 | """
27 | logger.debug(f"开始下载 {url} 本地路径: {local_path}")
28 | if os.path.exists(local_path) and refresh is False:
29 | logger.warning(f"{local_path} 已存在 不进行刷新处理")
30 | return
31 | down = cls.down_file_progress if progress else cls.down_file
32 | down(url, local_path)
33 |
34 | @classmethod
35 | def down_file(cls, url, local_path):
36 | session = requests.session()
37 | response = session.request(method='get', url=url, stream=True)
38 | with open(local_path, "wb") as code:
39 | code.write(response.content)
40 | print(f"{local_path} 下载完成 文件大小: {len(response.content) / 1024}kb")
41 |
42 | @classmethod
43 | def down_file_progress(cls, url, local_path):
44 | session = requests.session()
45 | response = session.request(method='get', url=url, stream=True)
46 | total = int(response.headers.get('content-length', 0))
47 | with open(local_path, 'wb') as file, tqdm(
48 | desc=local_path,
49 | total=total,
50 | unit='iB',
51 | unit_scale=True,
52 | unit_divisor=1024,
53 | ) as bar:
54 | for data in response.iter_content(chunk_size=1024):
55 | size = file.write(data)
56 | bar.update(size)
57 |
--------------------------------------------------------------------------------
/humo_utils/generates/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2021/12/28 14:47
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : __init__.py
7 | # @Software : PyCharm
8 | # @Description :
9 | from humo_utils.datetime_utils import get_birthday_date
10 | from humo_utils.generates.address import GenerateAddress
11 | from humo_utils.generates.card_no import GenerateCardNo
12 | from humo_utils.generates.mobile import GenerateMobile
13 | from humo_utils.generates.name import GenerateName
14 |
15 |
16 | def generate_card(age: str = None, birthday: str = None, sex: str = None, address: str = None):
17 | """
18 | 生成身份证号
19 | :param age: 年龄 当存在出生日期时 以出生日期为准
20 | :param birthday: 出生日期
21 | :param sex: 性别 1男 2女
22 | :param address: 地址 身份证编码前6位
23 | """
24 | birthday = birthday if birthday else get_birthday_date(age=age)
25 | return GenerateCardNo.card_no(birthday=birthday, sex=sex, address=address)
26 |
27 |
28 | def generate_name():
29 | """
30 | 生成姓名
31 | """
32 | return GenerateName.name()
33 |
34 |
35 | def generate_mobile():
36 | """
37 | 生成手机号
38 | """
39 | return GenerateMobile.mobile()
40 |
41 |
42 | def generate_address(address_no: str = None):
43 | """
44 | 生成地址
45 | :param address_no: 身份证编码前6位, 会生成符合身份证信息的地址
46 | """
47 | if address_no:
48 | return GenerateAddress.get_address(address_no)
49 | return GenerateAddress.get_random_address()
50 |
51 |
52 | def generate_identity_info(age: str = '20Y', sex: str = None) -> dict:
53 | """
54 | 生成身份信息
55 | :param age: 年龄
56 | :param sex: 性别
57 | :return:
58 | """
59 | card_no = generate_card(age=age, sex=sex)
60 | return {
61 | 'card_no': card_no,
62 | 'address': generate_address(card_no[0:6]),
63 | 'name': generate_name(),
64 | 'mobile': generate_mobile()
65 | }
66 |
--------------------------------------------------------------------------------
/humo_utils/generates/address.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2021/6/29 下午7:02
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : address.py
7 | # @Software : PyCharm
8 | # @Description : 生成地址
9 | import random
10 | from humo_utils.generates import area_data
11 |
12 |
13 | class GenerateAddress(object):
14 | area_list = area_data.area_list
15 |
16 | @classmethod
17 | def get_random_area(cls):
18 | """获取包含最细粒度的随机地区编码及地址"""
19 | name = ""
20 | province_len = len(cls.area_list)
21 | province = cls.area_list[random.randint(0, province_len - 1)]
22 | name += province.get("label")
23 |
24 | city_len = len(province.get("children"))
25 | if city_len == 0:
26 | card_no = province.get("value")
27 | return {"value": card_no, "label": name}
28 | else:
29 | city = province.get("children")[random.randint(0, city_len - 1)]
30 | name += city.get("label")
31 |
32 | county_len = len(city.get("children"))
33 | if county_len == 0:
34 | card_no = city.get("value")
35 | return {"value": card_no, "label": name}
36 | else:
37 | county = city.get("children")[random.randint(
38 | 0, county_len - 1)]
39 | name += county.get("label")
40 | street_len = len(county.get("children"))
41 | if street_len == 0:
42 | card_no = county.get("value")
43 | return {"value": card_no, "label": name}
44 | else:
45 | street = county.get("children")[random.randint(
46 | 0, street_len - 1)]
47 | name += street.get("label")
48 | card_no = street.get("value")
49 | return {"value": card_no, "label": name}
50 |
51 | @classmethod
52 | def get_random_address(cls):
53 | """获取随机地址"""
54 | return cls.get_random_area().get("label")
55 |
56 | @classmethod
57 | def get_address(cls, address_no):
58 | """根据身份证前6位 获取指定的最细粒度地址"""
59 | address = ""
60 | for province in cls.area_list:
61 | if province.get("value") == address_no[0:2]:
62 | address += province.get("label")
63 | for city in province.get("children"):
64 | if city.get("value") == address_no[0:4]:
65 | address += city.get("label")
66 | for county in city.get("children"):
67 | if county.get("value") == address_no[0:6]:
68 | address += county.get("label")
69 | street = county.get("children")[random.randint(0, len(county.get("children")) - 1)]
70 | address += street.get("label")
71 | return address + cls.get_random_estate()
72 |
73 | @classmethod
74 | def get_random_estate(cls):
75 | """随机生成街道小区信息"""
76 | common_name = ["聚源", "佳福", "驿乐", "源达", "华邦", "凯撒", "同阳", "美乐", "华尔顿", "天胜",
77 | "金豪", "鹏晖", "金雅", "雅盛", "菲特", "协邦", "龙桦", "麦豪", "盛达", "荣盛",
78 | "格林", "汇都", "七福", "富臣", "名豪", "裕福", "元一", "宏福", "世尊", "京华",
79 | "城轩", "永嘉", "诚尔", "梦泰", "富华", "尔乐", "银都", "顺生", "金角", "领立",
80 | "鑫荣", "友荣", "鼎盛", "国鼎", "双屿", "富丽", "温沙", "亿凯", "鸿华", "星辉",
81 | "宏达", "博亿", "乐从", "客轩", "金锐", "天都", "君悦", "赢天", "熙和", "派高",
82 | "博玛", "润新", "东蒙", "利来", "国聚", "艺诺", "诚悦", "杰宏", "文华", "美特",
83 | "锐恒", "泰唐", "裕通", "永新", "兴源", "金旺", "舒雅", "正阳", "荣兴", "云天",
84 | "喜象", "天龙", "银马", "诚达", "鑫汉", "玛格", "中诺", "锦都", "晟丰", "凯豪",
85 | "柏菲", "华龙", "伟艺", "菲斯", "金跃", "顺冠", "铭科", "洲泰", "简艺", "诺信",
86 | "优嘉", "名鸿", "江恒", "蓝图", "诚栋", "家家顺", "新家园", "银地", "华瑞", "汇德",
87 | "易安居", "金航", "创元", "宏轩", "兴扬", "新瑞", "融居", "捷辰", "家客多", "优置客",
88 | "华瑞", "香河永成", "优享逸栈", "元诚", "凯丽", "世豫", "宜安家", "松鹤", "鑫鸿",
89 | "兴海", "银兴", "阳光沙滩", "温尚居", "盈盛", "兴盛", "迅杰", "金典", "兴凯", "吉星", "东佳",
90 | "安厦", "隆志达", "江山大地", "玉溪北苑", "博源", "锦裕达", "和诚", "水源丰", "境胜", "爱家立业",
91 | "华杰", "盛世恒业", "泰源", "华冠", "大溪地", "天地", "信地", "三得益", "房信", "东方",
92 | "派拉蒙", "深淼", "河源", "富园", "金源", "百大", "兴达", "恩宝", "玖月", "嘉锦鹏", "益民",
93 | "光怡", "德信", "八达", "富中", "国正", "奥新", "安青", "巴人", "东镜", "丰泽", "丰力", "峰岩",
94 | "飞扬", "伟峰", "城铭", "村田", "大富", "大商", "星渊", "信拓", "协和", "缘通", "元凌", "远志",
95 | "金地", "玉鸣", "西欧", "锄禾", "创坛", "住达", "众合", "永恒", "朝河源", "馨园", "鑫诚", "颐豪",
96 | "亿华", "驿鑫", "普瑞", "强锐", "福地", "长城", "神剑", "瑞贝卡", "日盛达", "瑞邦", "三盛",
97 | "荣城",
98 | "深化", "松鹤", "随缘", "思维", "圣田", "盛和", "天昊", "天晟", "万方", "万邦", "图腾", "泰龙",
99 | "桃园", "腾飞", "天创", "开源", "奎世", "君意", "聚缘居", "鲲鹏", "蓝石", "华美", "百家兴",
100 | "京御幸福", "同心", "中佳", "地球村", "居佳", "鼎盛居", "方大", "纵横", "青商", "文振", "豫建",
101 | "金居", "吉星", "南洋", "天地恒", "广龙", "纬凌特", "欧佳", "天地中", "万赢", "广通达", "玉山",
102 | "同富康", "恒威", "永辉"]
103 | suffix = ["小区", "华庭", "苑", "湾", "府", "国际公寓", "海岸", "园", "堡"]
104 | digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
105 |
106 | return f"{random.choice(common_name)}{random.choice(suffix)}{random.choice(digits)}栋{random.choice(digits)}0{random.choice(digits)}号"
107 |
--------------------------------------------------------------------------------
/humo_utils/generates/card_no.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2021/6/29 下午7:00
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : card_no.py
7 | # @Software : PyCharm
8 | # @Description : 生成身份证号
9 |
10 | import random
11 | import string
12 |
13 | address_list = ['110101', '110102', '110105', '110106', '110107', '110108', '110109', '110111', '110112', '110113',
14 | '110114', '110115', '110116', '110117', '110118', '110119', '120101', '120102', '120103', '120104',
15 | '120105', '120106', '120110', '120111', '120112', '120113', '120114', '120115', '120116', '120117',
16 | '120118', '120119', '130102', '130104', '130105', '130107', '130108', '130109', '130110', '130111',
17 | '130121', '130123', '130125', '130126', '130127', '130128', '130129', '130130', '130131', '130132',
18 | '130133', '130171', '130172', '130181', '130183', '130184', '130202', '130203', '130204', '130205',
19 | '130207', '130208', '130209', '130224', '130225', '130227', '130229', '130271', '130272', '130273',
20 | '130274', '130281', '130283', '130284', '130302', '130303', '130304', '130306', '130321', '130322',
21 | '130324', '130371', '130372', '130402', '130403', '130404', '130406', '130407', '130408', '130423',
22 | '130424', '130425', '130426', '130427', '130430', '130431', '130432', '130433', '130434', '130435',
23 | '130471', '130473', '130481', '130502', '130503', '130505', '130506', '130522', '130523', '130524',
24 | '130525', '130528', '130529', '130530', '130531', '130532', '130533', '130534', '130535', '130571',
25 | '130581', '130582', '130602', '130606', '130607', '130608', '130609', '130623', '130624', '130626',
26 | '130627', '130628', '130629', '130630', '130631', '130632', '130633', '130634', '130635', '130636',
27 | '130637', '130638', '130671', '130672', '130681', '130682', '130683', '130684', '130702', '130703',
28 | '130705', '130706', '130708', '130709', '130722', '130723', '130724', '130725', '130726', '130727',
29 | '130728', '130730', '130731', '130732', '130771', '130772', '130773', '130802', '130803', '130804',
30 | '130821', '130822', '130824', '130825', '130826', '130827', '130828', '130871', '130881', '130902',
31 | '130903', '130921', '130922', '130923', '130924', '130925', '130926', '130927', '130928', '130929',
32 | '130930', '130971', '130972', '130973', '130981', '130982', '130983', '130984', '131002', '131003',
33 | '131022', '131023', '131024', '131025', '131026', '131028', '131071', '131081', '131082', '131102',
34 | '131103', '131121', '131122', '131123', '131124', '131125', '131126', '131127', '131128', '131171',
35 | '131172', '131182', '140105', '140106', '140107', '140108', '140109', '140110', '140121', '140122',
36 | '140123', '140171', '140181', '140212', '140213', '140214', '140215', '140221', '140222', '140223',
37 | '140224', '140225', '140226', '140271', '140302', '140303', '140311', '140321', '140322', '140403',
38 | '140404', '140405', '140406', '140423', '140425', '140426', '140427', '140428', '140429', '140430',
39 | '140431', '140471', '140502', '140521', '140522', '140524', '140525', '140581', '140602', '140603',
40 | '140621', '140622', '140623', '140671', '140681', '140702', '140703', '140721', '140722', '140723',
41 | '140724', '140725', '140727', '140728', '140729', '140781', '140802', '140821', '140822', '140823',
42 | '140824', '140825', '140826', '140827', '140828', '140829', '140830', '140881', '140882', '140902',
43 | '140921', '140922', '140923', '140924', '140925', '140926', '140927', '140928', '140929', '140930',
44 | '140931', '140932', '140971', '140981', '141002', '141021', '141022', '141023', '141024', '141025',
45 | '141026', '141027', '141028', '141029', '141030', '141031', '141032', '141033', '141034', '141081',
46 | '141082', '141102', '141121', '141122', '141123', '141124', '141125', '141126', '141127', '141128',
47 | '141129', '141130', '141181', '141182', '150102', '150103', '150104', '150105', '150121', '150122',
48 | '150123', '150124', '150125', '150172', '150202', '150203', '150204', '150205', '150206', '150207',
49 | '150221', '150222', '150223', '150271', '150302', '150303', '150304', '150402', '150403', '150404',
50 | '150421', '150422', '150423', '150424', '150425', '150426', '150428', '150429', '150430', '150502',
51 | '150521', '150522', '150523', '150524', '150525', '150526', '150571', '150581', '150602', '150603',
52 | '150621', '150622', '150623', '150624', '150625', '150626', '150627', '150702', '150703', '150721',
53 | '150722', '150723', '150724', '150725', '150726', '150727', '150781', '150782', '150783', '150784',
54 | '150785', '150802', '150821', '150822', '150823', '150824', '150825', '150826', '150902', '150921',
55 | '150922', '150923', '150924', '150925', '150926', '150927', '150928', '150929', '150981', '152201',
56 | '152202', '152221', '152222', '152223', '152224', '152501', '152502', '152522', '152523', '152524',
57 | '152525', '152526', '152527', '152528', '152529', '152530', '152531', '152571', '152921', '152922',
58 | '152923', '152971', '210102', '210103', '210104', '210105', '210106', '210111', '210112', '210113',
59 | '210114', '210115', '210123', '210124', '210181', '210202', '210203', '210204', '210211', '210212',
60 | '210213', '210214', '210224', '210281', '210283', '210302', '210303', '210304', '210311', '210321',
61 | '210323', '210381', '210402', '210403', '210404', '210411', '210421', '210422', '210423', '210502',
62 | '210503', '210504', '210505', '210521', '210522', '210602', '210603', '210604', '210624', '210681',
63 | '210682', '210702', '210703', '210711', '210726', '210727', '210781', '210782', '210802', '210803',
64 | '210804', '210811', '210881', '210882', '210902', '210903', '210904', '210905', '210911', '210921',
65 | '210922', '211002', '211003', '211004', '211005', '211011', '211021', '211081', '211102', '211103',
66 | '211104', '211122', '211202', '211204', '211221', '211223', '211224', '211281', '211282', '211302',
67 | '211303', '211321', '211322', '211324', '211381', '211382', '211402', '211403', '211404', '211421',
68 | '211422', '211481', '220102', '220103', '220104', '220105', '220106', '220112', '220113', '220122',
69 | '220171', '220172', '220173', '220174', '220182', '220183', '220184', '220202', '220203', '220204',
70 | '220211', '220221', '220271', '220272', '220273', '220281', '220282', '220283', '220284', '220302',
71 | '220303', '220322', '220323', '220382', '220402', '220403', '220421', '220422', '220502', '220503',
72 | '220521', '220523', '220524', '220581', '220582', '220602', '220605', '220621', '220622', '220623',
73 | '220681', '220702', '220721', '220722', '220723', '220771', '220781', '220802', '220821', '220822',
74 | '220871', '220881', '220882', '222401', '222402', '222403', '222404', '222405', '222406', '222424',
75 | '222426', '230102', '230103', '230104', '230108', '230109', '230110', '230111', '230112', '230113',
76 | '230123', '230124', '230125', '230126', '230127', '230128', '230129', '230183', '230184', '230202',
77 | '230203', '230204', '230205', '230206', '230207', '230208', '230221', '230223', '230224', '230225',
78 | '230227', '230229', '230230', '230231', '230281', '230302', '230303', '230304', '230305', '230306',
79 | '230307', '230321', '230381', '230382', '230402', '230403', '230404', '230405', '230406', '230407',
80 | '230421', '230422', '230502', '230503', '230505', '230506', '230521', '230522', '230523', '230524',
81 | '230602', '230603', '230604', '230605', '230606', '230621', '230622', '230623', '230624', '230671',
82 | '230717', '230718', '230719', '230722', '230723', '230724', '230725', '230726', '230751', '230781',
83 | '230803', '230804', '230805', '230811', '230822', '230826', '230828', '230881', '230882', '230883',
84 | '230902', '230903', '230904', '230921', '231002', '231003', '231004', '231005', '231025', '231071',
85 | '231081', '231083', '231084', '231085', '231086', '231102', '231123', '231124', '231181', '231182',
86 | '231183', '231202', '231221', '231222', '231223', '231224', '231225', '231226', '231281', '231282',
87 | '231283', '232701', '232721', '232722', '232761', '232762', '232763', '232764', '310101', '310104',
88 | '310105', '310106', '310107', '310109', '310110', '310112', '310113', '310114', '310115', '310116',
89 | '310117', '310118', '310120', '310151', '320102', '320104', '320105', '320106', '320111', '320113',
90 | '320114', '320115', '320116', '320117', '320118', '320205', '320206', '320211', '320213', '320214',
91 | '320281', '320282', '320302', '320303', '320305', '320311', '320312', '320321', '320322', '320324',
92 | '320371', '320381', '320382', '320402', '320404', '320411', '320412', '320413', '320481', '320505',
93 | '320506', '320507', '320508', '320509', '320571', '320581', '320582', '320583', '320585', '320602',
94 | '320611', '320612', '320623', '320671', '320681', '320682', '320684', '320685', '320703', '320706',
95 | '320707', '320722', '320723', '320724', '320771', '320772', '320803', '320804', '320812', '320813',
96 | '320826', '320830', '320831', '320871', '320902', '320903', '320904', '320921', '320922', '320923',
97 | '320924', '320925', '320971', '320981', '321002', '321003', '321012', '321023', '321071', '321081',
98 | '321084', '321102', '321111', '321112', '321171', '321181', '321182', '321183', '321202', '321203',
99 | '321204', '321271', '321281', '321282', '321283', '321302', '321311', '321322', '321323', '321324',
100 | '321371', '330102', '330103', '330104', '330105', '330106', '330108', '330109', '330110', '330111',
101 | '330112', '330122', '330127', '330182', '330203', '330205', '330206', '330211', '330212', '330213',
102 | '330225', '330226', '330281', '330282', '330302', '330303', '330304', '330305', '330324', '330326',
103 | '330327', '330328', '330329', '330371', '330381', '330382', '330383', '330402', '330411', '330421',
104 | '330424', '330481', '330482', '330483', '330502', '330503', '330521', '330522', '330523', '330602',
105 | '330603', '330604', '330624', '330681', '330683', '330702', '330703', '330723', '330726', '330727',
106 | '330781', '330782', '330783', '330784', '330802', '330803', '330822', '330824', '330825', '330881',
107 | '330902', '330903', '330921', '330922', '331002', '331003', '331004', '331022', '331023', '331024',
108 | '331081', '331082', '331083', '331102', '331121', '331122', '331123', '331124', '331125', '331126',
109 | '331127', '331181', '340102', '340103', '340104', '340111', '340121', '340122', '340123', '340124',
110 | '340171', '340172', '340173', '340181', '340202', '340203', '340207', '340208', '340221', '340222',
111 | '340223', '340271', '340272', '340281', '340302', '340303', '340304', '340311', '340321', '340322',
112 | '340323', '340371', '340372', '340402', '340403', '340404', '340405', '340406', '340421', '340422',
113 | '340503', '340504', '340506', '340521', '340522', '340523', '340602', '340603', '340604', '340621',
114 | '340705', '340706', '340711', '340722', '340802', '340803', '340811', '340822', '340825', '340826',
115 | '340827', '340828', '340871', '340881', '340882', '341002', '341003', '341004', '341021', '341022',
116 | '341023', '341024', '341102', '341103', '341122', '341124', '341125', '341126', '341171', '341172',
117 | '341181', '341182', '341202', '341203', '341204', '341221', '341222', '341225', '341226', '341271',
118 | '341272', '341282', '341302', '341321', '341322', '341323', '341324', '341371', '341372', '341502',
119 | '341503', '341504', '341522', '341523', '341524', '341525', '341602', '341621', '341622', '341623',
120 | '341702', '341721', '341722', '341723', '341802', '341821', '341823', '341824', '341825', '341871',
121 | '341881', '341882', '350102', '350103', '350104', '350105', '350111', '350112', '350121', '350122',
122 | '350123', '350124', '350125', '350128', '350181', '350203', '350205', '350206', '350211', '350212',
123 | '350213', '350302', '350303', '350304', '350305', '350322', '350402', '350403', '350421', '350423',
124 | '350424', '350425', '350426', '350427', '350428', '350429', '350430', '350481', '350502', '350503',
125 | '350504', '350505', '350521', '350524', '350525', '350526', '350527', '350581', '350582', '350583',
126 | '350602', '350603', '350622', '350623', '350624', '350625', '350626', '350627', '350628', '350629',
127 | '350681', '350702', '350703', '350721', '350722', '350723', '350724', '350725', '350781', '350782',
128 | '350783', '350802', '350803', '350821', '350823', '350824', '350825', '350881', '350902', '350921',
129 | '350922', '350923', '350924', '350925', '350926', '350981', '350982', '360102', '360103', '360104',
130 | '360111', '360112', '360113', '360121', '360123', '360124', '360202', '360203', '360222', '360281',
131 | '360302', '360313', '360321', '360322', '360323', '360402', '360403', '360404', '360423', '360424',
132 | '360425', '360426', '360428', '360429', '360430', '360481', '360482', '360483', '360502', '360521',
133 | '360602', '360603', '360681', '360702', '360703', '360704', '360722', '360723', '360724', '360725',
134 | '360726', '360728', '360729', '360730', '360731', '360732', '360733', '360734', '360735', '360781',
135 | '360783', '360802', '360803', '360821', '360822', '360823', '360824', '360825', '360826', '360827',
136 | '360828', '360829', '360830', '360881', '360902', '360921', '360922', '360923', '360924', '360925',
137 | '360926', '360981', '360982', '360983', '361002', '361003', '361021', '361022', '361023', '361024',
138 | '361025', '361026', '361027', '361028', '361030', '361102', '361103', '361104', '361123', '361124',
139 | '361125', '361126', '361127', '361128', '361129', '361130', '361181', '370102', '370103', '370104',
140 | '370105', '370112', '370113', '370114', '370115', '370116', '370117', '370124', '370126', '370171',
141 | '370202', '370203', '370211', '370212', '370213', '370214', '370215', '370271', '370281', '370283',
142 | '370285', '370302', '370303', '370304', '370305', '370306', '370321', '370322', '370323', '370402',
143 | '370403', '370404', '370405', '370406', '370481', '370502', '370503', '370505', '370522', '370523',
144 | '370571', '370572', '370602', '370611', '370612', '370613', '370614', '370671', '370672', '370681',
145 | '370682', '370683', '370685', '370686', '370687', '370702', '370703', '370704', '370705', '370724',
146 | '370725', '370772', '370781', '370782', '370783', '370784', '370785', '370786', '370811', '370812',
147 | '370826', '370827', '370828', '370829', '370830', '370831', '370832', '370871', '370881', '370883',
148 | '370902', '370911', '370921', '370923', '370982', '370983', '371002', '371003', '371071', '371072',
149 | '371073', '371082', '371083', '371102', '371103', '371121', '371122', '371171', '371302', '371311',
150 | '371312', '371321', '371322', '371323', '371324', '371325', '371326', '371327', '371328', '371329',
151 | '371371', '371402', '371403', '371422', '371423', '371424', '371425', '371426', '371427', '371428',
152 | '371471', '371472', '371481', '371482', '371502', '371503', '371521', '371522', '371524', '371525',
153 | '371526', '371581', '371602', '371603', '371621', '371622', '371623', '371625', '371681', '371702',
154 | '371703', '371721', '371722', '371723', '371724', '371725', '371726', '371728', '371771', '371772',
155 | '410102', '410103', '410104', '410105', '410106', '410108', '410122', '410171', '410172', '410173',
156 | '410181', '410182', '410183', '410184', '410185', '410202', '410203', '410204', '410205', '410212',
157 | '410221', '410222', '410223', '410225', '410302', '410303', '410304', '410305', '410306', '410311',
158 | '410322', '410323', '410324', '410325', '410326', '410327', '410328', '410329', '410371', '410381',
159 | '410402', '410403', '410404', '410411', '410421', '410422', '410423', '410425', '410471', '410472',
160 | '410481', '410482', '410502', '410503', '410505', '410506', '410522', '410523', '410526', '410527',
161 | '410571', '410581', '410602', '410603', '410611', '410621', '410622', '410671', '410702', '410703',
162 | '410704', '410711', '410721', '410724', '410725', '410726', '410727', '410771', '410772', '410773',
163 | '410781', '410782', '410783', '410802', '410803', '410804', '410811', '410821', '410822', '410823',
164 | '410825', '410871', '410882', '410883', '410902', '410922', '410923', '410926', '410927', '410928',
165 | '410971', '410972', '411002', '411003', '411024', '411025', '411071', '411081', '411082', '411102',
166 | '411103', '411104', '411121', '411122', '411171', '411202', '411203', '411221', '411224', '411271',
167 | '411281', '411282', '411302', '411303', '411321', '411322', '411323', '411324', '411325', '411326',
168 | '411327', '411328', '411329', '411330', '411371', '411372', '411381', '411402', '411403', '411421',
169 | '411422', '411423', '411424', '411425', '411426', '411471', '411472', '411481', '411502', '411503',
170 | '411521', '411522', '411523', '411524', '411525', '411526', '411527', '411528', '411571', '411602',
171 | '411603', '411621', '411622', '411623', '411624', '411625', '411627', '411628', '411671', '411681',
172 | '411702', '411721', '411722', '411723', '411724', '411725', '411726', '411727', '411728', '411729',
173 | '411771', '419001', '420102', '420103', '420104', '420105', '420106', '420107', '420111', '420112',
174 | '420113', '420114', '420115', '420116', '420117', '420202', '420203', '420204', '420205', '420222',
175 | '420281', '420302', '420303', '420304', '420322', '420323', '420324', '420325', '420381', '420502',
176 | '420503', '420504', '420505', '420506', '420525', '420526', '420527', '420528', '420529', '420581',
177 | '420582', '420583', '420602', '420606', '420607', '420624', '420625', '420626', '420682', '420683',
178 | '420684', '420702', '420703', '420704', '420802', '420804', '420822', '420881', '420882', '420902',
179 | '420921', '420922', '420923', '420981', '420982', '420984', '421002', '421003', '421022', '421023',
180 | '421024', '421071', '421081', '421083', '421087', '421102', '421121', '421122', '421123', '421124',
181 | '421125', '421126', '421127', '421171', '421181', '421182', '421202', '421221', '421222', '421223',
182 | '421224', '421281', '421303', '421321', '421381', '422801', '422802', '422822', '422823', '422825',
183 | '422826', '422827', '422828', '429004', '429005', '429006', '429021', '430102', '430103', '430104',
184 | '430105', '430111', '430112', '430121', '430181', '430182', '430202', '430203', '430204', '430211',
185 | '430212', '430223', '430224', '430225', '430271', '430281', '430302', '430304', '430321', '430371',
186 | '430372', '430373', '430381', '430382', '430405', '430406', '430407', '430408', '430412', '430421',
187 | '430422', '430423', '430424', '430426', '430471', '430472', '430473', '430481', '430482', '430502',
188 | '430503', '430511', '430522', '430523', '430524', '430525', '430527', '430528', '430529', '430581',
189 | '430582', '430602', '430603', '430611', '430621', '430623', '430624', '430626', '430671', '430681',
190 | '430682', '430702', '430703', '430721', '430722', '430723', '430724', '430725', '430726', '430771',
191 | '430781', '430802', '430811', '430821', '430822', '430902', '430903', '430921', '430922', '430923',
192 | '430971', '430972', '430981', '431002', '431003', '431021', '431022', '431023', '431024', '431025',
193 | '431026', '431027', '431028', '431081', '431102', '431103', '431121', '431122', '431123', '431124',
194 | '431125', '431126', '431127', '431128', '431129', '431171', '431172', '431173', '431202', '431221',
195 | '431222', '431223', '431224', '431225', '431226', '431227', '431228', '431229', '431230', '431271',
196 | '431281', '431302', '431321', '431322', '431381', '431382', '433101', '433122', '433123', '433124',
197 | '433125', '433126', '433127', '433130', '440103', '440104', '440105', '440106', '440111', '440112',
198 | '440113', '440114', '440115', '440117', '440118', '440203', '440204', '440205', '440222', '440224',
199 | '440229', '440232', '440233', '440281', '440282', '440303', '440304', '440305', '440306', '440307',
200 | '440308', '440309', '440310', '440311', '440402', '440403', '440404', '440507', '440511', '440512',
201 | '440513', '440514', '440515', '440523', '440604', '440605', '440606', '440607', '440608', '440703',
202 | '440704', '440705', '440781', '440783', '440784', '440785', '440802', '440803', '440804', '440811',
203 | '440823', '440825', '440881', '440882', '440883', '440902', '440904', '440981', '440982', '440983',
204 | '441202', '441203', '441204', '441223', '441224', '441225', '441226', '441284', '441302', '441303',
205 | '441322', '441323', '441324', '441402', '441403', '441422', '441423', '441424', '441426', '441427',
206 | '441481', '441502', '441521', '441523', '441581', '441602', '441621', '441622', '441623', '441624',
207 | '441625', '441702', '441704', '441721', '441781', '441802', '441803', '441821', '441823', '441825',
208 | '441826', '441881', '441882', '441900', '442000', '445102', '445103', '445122', '445202', '445203',
209 | '445222', '445224', '445281', '445302', '445303', '445321', '445322', '445381', '450102', '450103',
210 | '450105', '450107', '450108', '450109', '450110', '450123', '450124', '450125', '450126', '450127',
211 | '450202', '450203', '450204', '450205', '450206', '450222', '450223', '450224', '450225', '450226',
212 | '450302', '450303', '450304', '450305', '450311', '450312', '450321', '450323', '450324', '450325',
213 | '450326', '450327', '450328', '450329', '450330', '450332', '450381', '450403', '450405', '450406',
214 | '450421', '450422', '450423', '450481', '450502', '450503', '450512', '450521', '450602', '450603',
215 | '450621', '450681', '450702', '450703', '450721', '450722', '450802', '450803', '450804', '450821',
216 | '450881', '450902', '450903', '450921', '450922', '450923', '450924', '450981', '451002', '451003',
217 | '451022', '451024', '451026', '451027', '451028', '451029', '451030', '451031', '451081', '451082',
218 | '451102', '451103', '451121', '451122', '451123', '451202', '451203', '451221', '451222', '451223',
219 | '451224', '451225', '451226', '451227', '451228', '451229', '451302', '451321', '451322', '451323',
220 | '451324', '451381', '451402', '451421', '451422', '451423', '451424', '451425', '451481', '460105',
221 | '460106', '460107', '460108', '460202', '460203', '460204', '460205', '460321', '460322', '460323',
222 | '460400', '469001', '469002', '469005', '469006', '469007', '469021', '469022', '469023', '469024',
223 | '469025', '469026', '469027', '469028', '469029', '469030', '500101', '500102', '500103', '500104',
224 | '500105', '500106', '500107', '500108', '500109', '500110', '500111', '500112', '500113', '500114',
225 | '500115', '500116', '500117', '500118', '500119', '500120', '500151', '500152', '500153', '500154',
226 | '500155', '500156', '500229', '500230', '500231', '500233', '500235', '500236', '500237', '500238',
227 | '500240', '500241', '500242', '500243', '510104', '510105', '510106', '510107', '510108', '510112',
228 | '510113', '510114', '510115', '510116', '510117', '510118', '510121', '510129', '510131', '510181',
229 | '510182', '510183', '510184', '510185', '510302', '510303', '510304', '510311', '510321', '510322',
230 | '510402', '510403', '510411', '510421', '510422', '510502', '510503', '510504', '510521', '510522',
231 | '510524', '510525', '510603', '510604', '510623', '510681', '510682', '510683', '510703', '510704',
232 | '510705', '510722', '510723', '510725', '510726', '510727', '510781', '510802', '510811', '510812',
233 | '510821', '510822', '510823', '510824', '510903', '510904', '510921', '510923', '510981', '511002',
234 | '511011', '511024', '511025', '511071', '511083', '511102', '511111', '511112', '511113', '511123',
235 | '511124', '511126', '511129', '511132', '511133', '511181', '511302', '511303', '511304', '511321',
236 | '511322', '511323', '511324', '511325', '511381', '511402', '511403', '511421', '511423', '511424',
237 | '511425', '511502', '511503', '511504', '511523', '511524', '511525', '511526', '511527', '511528',
238 | '511529', '511602', '511603', '511621', '511622', '511623', '511681', '511702', '511703', '511722',
239 | '511723', '511724', '511725', '511771', '511781', '511802', '511803', '511822', '511823', '511824',
240 | '511825', '511826', '511827', '511902', '511903', '511921', '511922', '511923', '511971', '512002',
241 | '512021', '512022', '513201', '513221', '513222', '513223', '513224', '513225', '513226', '513227',
242 | '513228', '513230', '513231', '513232', '513233', '513301', '513322', '513323', '513324', '513325',
243 | '513326', '513327', '513328', '513329', '513330', '513331', '513332', '513333', '513334', '513335',
244 | '513336', '513337', '513338', '513401', '513422', '513423', '513424', '513425', '513426', '513427',
245 | '513428', '513429', '513430', '513431', '513432', '513433', '513434', '513435', '513436', '513437',
246 | '520102', '520103', '520111', '520112', '520113', '520115', '520121', '520122', '520123', '520181',
247 | '520201', '520203', '520221', '520281', '520302', '520303', '520304', '520322', '520323', '520324',
248 | '520325', '520326', '520327', '520328', '520329', '520330', '520381', '520382', '520402', '520403',
249 | '520422', '520423', '520424', '520425', '520502', '520521', '520522', '520523', '520524', '520525',
250 | '520526', '520527', '520602', '520603', '520621', '520622', '520623', '520624', '520625', '520626',
251 | '520627', '520628', '522301', '522302', '522323', '522324', '522325', '522326', '522327', '522328',
252 | '522601', '522622', '522623', '522624', '522625', '522626', '522627', '522628', '522629', '522630',
253 | '522631', '522632', '522633', '522634', '522635', '522636', '522701', '522702', '522722', '522723',
254 | '522725', '522726', '522727', '522728', '522729', '522730', '522731', '522732', '530102', '530103',
255 | '530111', '530112', '530113', '530114', '530115', '530124', '530125', '530126', '530127', '530128',
256 | '530129', '530181', '530302', '530303', '530304', '530322', '530323', '530324', '530325', '530326',
257 | '530381', '530402', '530403', '530423', '530424', '530425', '530426', '530427', '530428', '530481',
258 | '530502', '530521', '530523', '530524', '530581', '530602', '530621', '530622', '530623', '530624',
259 | '530625', '530626', '530627', '530628', '530629', '530681', '530702', '530721', '530722', '530723',
260 | '530724', '530802', '530821', '530822', '530823', '530824', '530825', '530826', '530827', '530828',
261 | '530829', '530902', '530921', '530922', '530923', '530924', '530925', '530926', '530927', '532301',
262 | '532322', '532323', '532324', '532325', '532326', '532327', '532328', '532329', '532331', '532501',
263 | '532502', '532503', '532504', '532523', '532524', '532525', '532527', '532528', '532529', '532530',
264 | '532531', '532532', '532601', '532622', '532623', '532624', '532625', '532626', '532627', '532628',
265 | '532801', '532822', '532823', '532901', '532922', '532923', '532924', '532925', '532926', '532927',
266 | '532928', '532929', '532930', '532931', '532932', '533102', '533103', '533122', '533123', '533124',
267 | '533301', '533323', '533324', '533325', '533401', '533422', '533423', '540102', '540103', '540104',
268 | '540121', '540122', '540123', '540124', '540127', '540171', '540172', '540173', '540174', '540202',
269 | '540221', '540222', '540223', '540224', '540225', '540226', '540227', '540228', '540229', '540230',
270 | '540231', '540232', '540233', '540234', '540235', '540236', '540237', '540302', '540321', '540322',
271 | '540323', '540324', '540325', '540326', '540327', '540328', '540329', '540330', '540402', '540421',
272 | '540422', '540423', '540424', '540425', '540426', '540502', '540521', '540522', '540523', '540524',
273 | '540525', '540526', '540527', '540528', '540529', '540530', '540531', '540602', '540621', '540622',
274 | '540623', '540624', '540625', '540626', '540627', '540628', '540629', '540630', '542521', '542522',
275 | '542523', '542524', '542525', '542526', '542527', '610102', '610103', '610104', '610111', '610112',
276 | '610113', '610114', '610115', '610116', '610117', '610118', '610122', '610124', '610202', '610203',
277 | '610204', '610222', '610302', '610303', '610304', '610322', '610323', '610324', '610326', '610327',
278 | '610328', '610329', '610330', '610331', '610402', '610403', '610404', '610422', '610423', '610424',
279 | '610425', '610426', '610428', '610429', '610430', '610431', '610481', '610482', '610502', '610503',
280 | '610522', '610523', '610524', '610525', '610526', '610527', '610528', '610581', '610582', '610602',
281 | '610603', '610621', '610622', '610625', '610626', '610627', '610628', '610629', '610630', '610631',
282 | '610632', '610681', '610702', '610703', '610722', '610723', '610724', '610725', '610726', '610727',
283 | '610728', '610729', '610730', '610802', '610803', '610822', '610824', '610825', '610826', '610827',
284 | '610828', '610829', '610830', '610831', '610881', '610902', '610921', '610922', '610923', '610924',
285 | '610925', '610926', '610927', '610928', '610929', '611002', '611021', '611022', '611023', '611024',
286 | '611025', '611026', '620102', '620103', '620104', '620105', '620111', '620121', '620122', '620123',
287 | '620171', '620201', '620302', '620321', '620402', '620403', '620421', '620422', '620423', '620502',
288 | '620503', '620521', '620522', '620523', '620524', '620525', '620602', '620621', '620622', '620623',
289 | '620702', '620721', '620722', '620723', '620724', '620725', '620802', '620821', '620822', '620823',
290 | '620825', '620826', '620881', '620902', '620921', '620922', '620923', '620924', '620981', '620982',
291 | '621002', '621021', '621022', '621023', '621024', '621025', '621026', '621027', '621102', '621121',
292 | '621122', '621123', '621124', '621125', '621126', '621202', '621221', '621222', '621223', '621224',
293 | '621225', '621226', '621227', '621228', '622901', '622921', '622922', '622923', '622924', '622925',
294 | '622926', '622927', '623001', '623021', '623022', '623023', '623024', '623025', '623026', '623027',
295 | '630102', '630103', '630104', '630105', '630106', '630121', '630123', '630202', '630203', '630222',
296 | '630223', '630224', '630225', '632221', '632222', '632223', '632224', '632321', '632322', '632323',
297 | '632324', '632521', '632522', '632523', '632524', '632525', '632621', '632622', '632623', '632624',
298 | '632625', '632626', '632701', '632722', '632723', '632724', '632725', '632726', '632801', '632802',
299 | '632803', '632821', '632822', '632823', '632857', '640104', '640105', '640106', '640121', '640122',
300 | '640181', '640202', '640205', '640221', '640302', '640303', '640323', '640324', '640381', '640402',
301 | '640422', '640423', '640424', '640425', '640502', '640521', '640522', '650102', '650103', '650104',
302 | '650105', '650106', '650107', '650109', '650121', '650202', '650203', '650204', '650205', '650402',
303 | '650421', '650422', '650502', '650521', '650522', '652301', '652302', '652323', '652324', '652325',
304 | '652327', '652328', '652701', '652702', '652722', '652723', '652801', '652822', '652823', '652824',
305 | '652825', '652826', '652827', '652828', '652829', '652871', '652901', '652902', '652922', '652924',
306 | '652925', '652926', '652927', '652928', '652929', '653001', '653022', '653023', '653024', '653101',
307 | '653121', '653122', '653123', '653124', '653125', '653126', '653127', '653128', '653129', '653130',
308 | '653131', '653201', '653221', '653222', '653223', '653224', '653225', '653226', '653227', '654002',
309 | '654003', '654004', '654021', '654022', '654023', '654024', '654025', '654026', '654027', '654028',
310 | '654201', '654202', '654221', '654223', '654224', '654225', '654226', '654301', '654321', '654322',
311 | '654323', '654324', '654325', '654326', '659001', '659002', '659003', '659004', '659005', '659006',
312 | '659007', '659008', '659009', '659010']
313 |
314 |
315 | class GenerateCardNo(object):
316 | @classmethod
317 | def __check(cls, prefix: str):
318 | """校验位计算"""
319 | var = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
320 | var_id = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]
321 | id_num = str(prefix)
322 | sum = 0
323 | for i in range(0, 17):
324 | sum += int(id_num[i]) * var[i]
325 | sum %= 11
326 | return var_id[sum]
327 |
328 | @classmethod
329 | def card_no(cls, birthday: str, sex: str = None, address: str = None):
330 | """
331 | 根据出生日期生成身份证号
332 | :param address: 地区编码
333 | :param birthday: 出生日期
334 | :param sex: 性别
335 | :return: card_no
336 | """
337 | address = address[0:6] if address else random.choice(address_list)
338 | birthday = birthday.replace("-", "").replace(" ", "").replace(":", "")
339 | if sex is None:
340 | sex = random.choice(string.digits)
341 | else:
342 | sex = random.choice("13579") if str(sex) == "1" else random.choice("24680")
343 | fill = str(random.randint(10, 99))
344 | prefix = f"{address}{birthday}{fill}{sex}"
345 | check = cls.__check(prefix)
346 | card_no = prefix + check
347 | return card_no
348 |
--------------------------------------------------------------------------------
/humo_utils/generates/mobile.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2021/6/29 下午7:01
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : mobile.py
7 | # @Software : PyCharm
8 | # @Description : 生成手机号
9 |
10 | import random
11 | import string
12 |
13 |
14 | class GenerateMobile(object):
15 | CMCC = ["139", "138", "137", "136", "135", "134", "159", "158", "157",
16 | "150", "151", "152", "188", "187", "182", "183", "184", "178"]
17 | CUCC = ["130", "131", "132", "156", "155", "186", "185", "176"]
18 | CTCC = ["133", "153", "189", "180", "181", "177"]
19 |
20 | @classmethod
21 | def __splice(cls, prefix_list):
22 | return str(random.choice(prefix_list)) + "".join(
23 | random.sample(string.digits, 8))
24 |
25 | @classmethod
26 | def cmcc_mobile(cls):
27 | """中国移动号段手机号"""
28 | return cls.__splice(cls.CMCC)
29 |
30 | @classmethod
31 | def cucc_mobile(cls):
32 | """中国联通号段手机号"""
33 | return cls.__splice(cls.CUCC)
34 |
35 | @classmethod
36 | def ctcc_mobile(cls):
37 | """中国电信号段手机号"""
38 | return cls.__splice(cls.CTCC)
39 |
40 | @classmethod
41 | def mobile(cls):
42 | return random.choice([cls.cucc_mobile(), cls.cmcc_mobile(), cls.ctcc_mobile()])
43 |
--------------------------------------------------------------------------------
/humo_utils/generates/name.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2021/6/29 下午7:01
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : name.py
7 | # @Software : PyCharm
8 | # @Description : 生成姓名
9 | import random
10 |
11 |
12 | class GenerateName(object):
13 | @classmethod
14 | def name_gbk(cls, length: int = 3):
15 | """
16 | 生成GBK2312编码的姓名
17 | gbk2312 收录了六千多常用汉字。
18 | 对字符的编码采用两个字节相组合。
19 | 第一个字节的范围是0xB0-0xF7,
20 | 第二个字节的范围是0xA1-0xFE。
21 | 主要为了测试生僻字姓名使用
22 | :param length: 长度
23 | :return:
24 | """
25 | name = ""
26 | for i in range(length):
27 | head = random.randint(176, 247)
28 | body = random.randint(161, 254)
29 | val = f"{head:x} {body:x}"
30 | name += "".join(
31 | bytes.fromhex(val).decode("gb2312", errors="ignore"))
32 |
33 | return "闾丘" + name
34 |
35 | @classmethod
36 | def name_unicode(cls, length: int = 3):
37 | """
38 | 生成unicode编码的姓名
39 | 在unicode码中,汉字的范围是(0x4E00, 9FBF)
40 | unicode码中收录了2万多个汉字,包含很多生僻的繁体字
41 | 主要为了测试生僻字姓名使用
42 | :param length: 长度
43 | :return:
44 | """
45 | names = list(chr(random.randint(19968, 40895)) for i in range(length))
46 | return "".join(names)
47 |
48 | @classmethod
49 | def name(cls, length: int = 3):
50 | """
51 | 生成符合firefly出单规则的姓名
52 | :param length: 长度
53 | :return:
54 | """
55 | name_str = "玥歆媛茹岚颖蓓欣璇曦弦韵蓓阳春琪蕾琬柔芝欣珊碧采婧梅华薇芳彬心颖梦华颖可鑫雪正茹优妍彤心蕾华欢婷帆妍歆漫露雯菡韵歆珊娜婷露蕾春雯"
56 | name = list(random.choice(name_str) for i in range(length))
57 | return "闾丘" + "".join(name)
58 |
--------------------------------------------------------------------------------
/humo_utils/zip/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # @Time : 2021/8/30 下午7:48
4 | # @Author : Mini-Right
5 | # @Email : www@anyu.wang
6 | # @File : zip.py
7 | # @Software : PyCharm
8 | # @Description :
9 | import os
10 | import zipfile
11 |
12 | from loguru import logger
13 |
14 |
15 | def write_all_file_to_zip(dir_path, zip_path):
16 | """
17 | :param dir_path: 要压缩的文件夹路径
18 | :param zip_path: 压缩后文件夹的路径 带zip
19 | :return:
20 | """
21 | logger.debug(f"压缩目标文件夹:{dir_path}")
22 | logger.debug(f"压缩目标文件夹名称:{zip_path}")
23 | z = zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED)
24 | for dir_path, dir_names, file_names in os.walk(dir_path):
25 | f_path = dir_path.replace(dir_path, "") # 这一句很重要,不replace的话,就从根目录开始复制
26 | f_path = f_path and f_path + os.sep or "" # 实现当前文件夹以及包含的所有文件的压缩
27 | for filename in file_names:
28 | logger.debug(f"压缩文件:{filename}")
29 | z.write(os.path.join(dir_path, filename), f_path + filename)
30 | z.close()
31 | logger.debug(f"压缩目标文件夹完成:{zip_path}")
32 | return zip_path
33 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | # This is a sample Python script.
2 |
3 | # Press ⌃R to execute it or replace it with your code.
4 | # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
5 |
6 |
7 | def print_hi(name):
8 | # Use a breakpoint in the code line below to debug your script.
9 | print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
10 |
11 |
12 | # Press the green button in the gutter to run the script.
13 | if __name__ == '__main__':
14 | print_hi('PyCharm')
15 |
16 | # See PyCharm help at https://www.jetbrains.com/help/pycharm/
17 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | arrow==1.2.2
2 | bleach==5.0.1
3 | certifi==2022.6.15
4 | charset-normalizer==2.1.0
5 | commonmark==0.9.1
6 | docutils==0.18.1
7 | idna==3.3
8 | importlib-metadata==4.12.0
9 | keyring==23.6.0
10 | loguru==0.6.0
11 | pkginfo==1.8.3
12 | Pygments==2.12.0
13 | PyMuPDF==1.20.1
14 | python-dateutil==2.8.2
15 | readme-renderer==35.0
16 | requests==2.28.1
17 | requests-toolbelt==0.9.1
18 | rfc3986==2.0.0
19 | rich==12.4.4
20 | six==1.16.0
21 | tqdm==4.64.0
22 | twine==4.0.1
23 | typing_extensions==4.3.0
24 | urllib3==1.26.9
25 | webencodings==0.5.1
26 | XlsxWriter==3.0.3
27 | zipp==3.8.0
28 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | # Inside of setup.cfg
2 | [metadata]
3 | description-file = README.md
4 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup
2 | from os import path
3 |
4 | import setuptools
5 |
6 | here = path.abspath(path.dirname(__file__))
7 |
8 | with open(path.join(here, 'requirements.txt'), 'r', encoding='utf-8') as f:
9 | all_reqs = f.read().split('\n')
10 | install_requires = [x.strip() for x in all_reqs if 'git+' not in x]
11 |
12 | with open(path.join(here, 'README.md'), 'r', encoding='utf-8') as f:
13 | long_description = f.read()
14 |
15 | setup(
16 | name='humo_utils', # 必填,项目的名字,用户根据这个名字安装,pip install humo_utils
17 | version='0.7', # 版本
18 | license='MIT', # 开源协议
19 | description='小右的常见工具类', # 项目描述
20 | author='Mini-Right', # 作者
21 | author_email='www@anyu.wang', # 邮箱
22 | url='https://github.com/Mini-Right/HumoUtils', # 项目的源码地址
23 | download_url='https://github.com/user/reponame/archive/v_01.tar.gz', # 源码下载地址
24 | keywords=['HUMO', 'UTILS', 'FastAPI'], # 关键词
25 | long_description=long_description, # 项目的详细说明,通常读取 README.md 文件的内容
26 | long_description_content_type="text/markdown", # # 描述的格式,可选的值: text/plain, text/x-rst, and text/markdown
27 | install_requires=install_requires, # 需要安装的依赖
28 | packages=setuptools.find_packages(), # 必填,指定打包的目录,默认是当前目录,如果是其他目录比如 src, 可以使用 find_packages(where='src')
29 | classifiers=[
30 | 'Development Status :: 3 - Alpha',
31 | # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
32 | 'Intended Audience :: Developers', # Define that your audience are developers
33 | 'Topic :: Software Development :: Build Tools',
34 | 'License :: OSI Approved :: MIT License', # Again, pick a license
35 | 'Programming Language :: Python :: 3', # Specify which pyhton versions that you want to support
36 | 'Programming Language :: Python :: 3.4',
37 | 'Programming Language :: Python :: 3.5',
38 | 'Programming Language :: Python :: 3.6',
39 | 'Programming Language :: Python :: 3.7',
40 | 'Programming Language :: Python :: 3.8',
41 | ],
42 | )
43 |
--------------------------------------------------------------------------------
/tea.yaml:
--------------------------------------------------------------------------------
1 | # https://tea.xyz/what-is-this-file
2 | ---
3 | version: 1.0.0
4 | codeOwners:
5 | - '0x4aE3641dcC6Ee3429138b0f55B38a7D26eF01f15'
6 | - '0xaBC385a167456D1EE6B4bDb9C28BbA3cfFaf5385'
7 | - '0x6799270713c1e182Eb5FE63ce7Da0FBe9D7B9d60'
8 | - '0x57E731f686688C263f10129953371Ea1f55bD20F'
9 | - '0xafE51A260FeC8Fd677A55ebfD2F413C8Db63B494'
10 | - '0xe21DC8E68Bd4014BFBDc410dd63684f4833fD2D4'
11 | - '0x0AaEF905BDA2702bBc31Cb6b03D55d05ef221708'
12 | - '0xc8D09Ce3C33f010B171768e7D13EFE7877c5435C'
13 | - '0x1cD867d237Cd121D9B278D521cD7D2162b57563d'
14 | - '0xfC1c019a8E6a7A3348A7ab84C413F1C9DcAB5278'
15 | - '0xC3f24898a988970bcA6A707f8E5A81E92D4676d8'
16 | - '0x14118720B2A30eAD0330e61698Cb1B575De48390'
17 | - '0x4c11CeEfb69a3C9C6AbF350316694973902e3eaD'
18 | - '0xde348B83ed21317B5b2300242Fdb3Adfa88F6549'
19 | - '0x7Df557189b464C23047979BBB9Da8d224B1A44b3'
20 | - '0xCcf10AC64d979fF2E88F8c01646361b1e0a08B8c'
21 | - '0xcA933b44F8C284C0C677f3Ae825f1b851C137C88'
22 | - '0x4B377d3e74B8fF8D37Bef4E0B09c8EC4c71e1E42'
23 | - '0x369d9eCd5EfA0202B996f50D8d8C571BEd4aFa0b'
24 | - '0xF6038906C05960fC007525C73d648B84b847d261'
25 | - '0x60439bFe0AD039e3Bd3AC7f51Dd06Ced761043D4'
26 | - '0xF822655229Caa1F75439127B3c3d4E24a54E203D'
27 | - '0x3772BcA3576D2Db8c58f1012E267a6a42F2415F2'
28 | - '0x5519ceeC1Ea2A02b18f2168169ADBD48f43FFdaB'
29 | - '0x1753F735E3137958080e26CFfBC187f6168f3B7A'
30 | - '0x88e57da88Cc970A366ED282916e3d9DC01949D4e'
31 | - '0x3C6c4864Ea4Fac22C3F1fA88C3DA087D7B6CA9BD'
32 | - '0x2990eb2968470c5b38229155cbDa11758F0C64d3'
33 | - '0x47776Ad401bF1b4235d8AA0A89a43b9AF93A9be8'
34 | - '0x8CCD39f4Ed8D68B5cbfad3E3AA943914a713B335'
35 | - '0xf47DB8429e11Eb50Bf2D710570e6384c2F86F08d'
36 | - '0xCEC3bD59Ac6193a4266267c055D1BA7C953b2182'
37 | - '0xA35e477449Baa7B68699055B4aF585A875cB5302'
38 | - '0x53Dd5D0355F193664E42e29bF1500dDc52b425BC'
39 | - '0x55ea57399E1500e29587e5bbd86f6DE2C6c449bf'
40 | - '0xe12D44719367399f13f19397Be679cBc49060Ea1'
41 | - '0x6Fe2558BaC227Cd2d93653BD98A30A04dC31A7ED'
42 | - '0xD8bD4CCF4e367732B02290F1dDEed4bee5f208cB'
43 | - '0xa7D3198F4B0BE1fba1403B80C7b42eF85C637562'
44 | - '0xAB636F54857A60a869418f568D9228eE951A199a'
45 | - '0xB86Be609484D3Ab365aCB295397dd67Fe08B8777'
46 | - '0xD48bB12c094C0b8Fb709912d6faE7cc5dE72FEB0'
47 | - '0x00E6504AEf82c41C6EC8786dF788a32A82854808'
48 | - '0xEE0301562dF786ae2c57FE4bf0FE7AB0Bd462859'
49 | - '0x49176424a9Fb8143FA4Dc75089502783f9670414'
50 | - '0xAEbB8815C8afd01F4365dc45606Eb76595d7afBd'
51 | - '0x936Feb91bcdc137e33B73767103E1CD6FfA7AcA6'
52 | - '0xc2b467f827c4Ade144d400F57921777544d194e0'
53 | - '0x76Cfd49edd6b73357078549dE9D6827205d13684'
54 | - '0xA8371Bf8cD1F99d736dae2d1fC897A2251CF1dD2'
55 | - '0x7905Fc91A3B3BA5A3d3dB750ee1775A62956faA6'
56 | - '0x8Ee56D18d6F1d8EC809948313E7719aB65A89a9e'
57 | - '0xc8B1E8A1C2fd25f304154D117b5f9b24e5873046'
58 | - '0xA57f7598aA7FB1a0292634578d11DB0a3818a5B1'
59 | - '0xA08342f497Ea960f0D5838E8D15D94FD5D9dE652'
60 | - '0xa6DAFe7345ab4b2A7eaE635943250405A8FFb629'
61 | - '0x5179656935D1c7dF8b1415c74776E984fEF4C840'
62 | - '0x8ACa8bB6d60f101CABdF9Db0DC132d601AB9b09E'
63 | - '0x1e0a7B9f47616fD690Fc9972DD1b4c2f9645895e'
64 | - '0xAaD73F633578C4907c09FcD089213d839a11F50F'
65 | - '0x54072dB861387302dC5913e29b739d3c27609796'
66 | - '0x6186721F60dCeE0112736fb9aD2367Ffd62Ed5f7'
67 | - '0xEA68430D8188469E3f36cFFcBb02c1736ba86eF2'
68 | - '0x65CC1C5bBC9Fa3E0c1641fcA8E771F4194c0674C'
69 | - '0x96BB54767A042F0feDF47a8e1B27C0180780A1a6'
70 | - '0x6dE635155d73aCF37aB3Ad7FBC81Cccc9b514ef7'
71 | - '0xE120EAC46B6b32DCE16315aDbA2700c914D61af9'
72 | - '0xfa33C64D828582e5252B425a71404FDB2c60D63f'
73 | - '0x557A939411Da140296fE7a37C9c46b7087cDB1cF'
74 | - '0x02F714915A49ad9C3fF19080dafe2c4D49A14754'
75 | - '0x1656F5c01Ed6830e040d0a700cc80310AEaB586E'
76 | - '0xfCF98AE45C9C8a17700c780637BCdE33a33a34F0'
77 | - '0xbCCAb31F234865E55BaF79D6854107F4E1e336F0'
78 | - '0xC1F29279D9663883Ba0a0D119c497a9f250A0Ea0'
79 | - '0xA2aBD3CEF0B4A8CD9320559c23D0E9eeCAe6DE76'
80 | - '0x26daCd1e23dcB202fEcD3f059dd53E2c94594b9B'
81 | - '0x7872fc42732FCe71E2aD834E1672c6d601935562'
82 | - '0x4940DCFf2146dd76526e9F3d5DeC823D61572c64'
83 | - '0xa794ad04FbD1a8F95E6d287d8192633d9a2A4510'
84 | - '0x83cE06aFC5340a4B1D7aE1CeBc2604c09E176be8'
85 | - '0xD393BE4E9679693aEF6D4a5ee20EA73EA0521481'
86 | - '0xf3d7f4B37bBc110d4cD1e2cC15D8395135ba9C6A'
87 | - '0xa04cBeCF6F30EA515a9A85BFE7ED73894d88ea18'
88 | - '0x713fe9eb89B2f07Ac38E20a225079b8Ba8E5c946'
89 | quorum: 1
90 |
--------------------------------------------------------------------------------