Compare commits
No commits in common. 'master' and 'main' have entirely different histories.
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -1,11 +0,0 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "7f7606f08e0544d8d012ef4d097dabdd6df6843a28793eb6551245d4b2db4242"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.8"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {},
|
||||
"develop": {}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/9/10 10:15
|
||||
# @Author : old tom
|
||||
# @File : fu_lang.py
|
||||
# @Project : Futool
|
||||
# @Desc : 字符串相关
|
@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/9/10 10:17
|
||||
# @Author : old tom
|
||||
# @File : fu_math.py
|
||||
# @Project : Futool
|
||||
# @Desc : 数学计算
|
@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/9/10 10:46
|
||||
# @Author : old tom
|
||||
# @File : fu_parser.py
|
||||
# @Project : Futool
|
||||
# @Desc : 解析器(CSV,JSON,NB文件)
|
@ -1,94 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/8/31 23:34
|
||||
# @Author : old tom
|
||||
# @File : http_downloader.py
|
||||
# @Project : Futool
|
||||
# @Desc : 文件下载器
|
||||
import time
|
||||
|
||||
from futool.http.http_request import head
|
||||
from multiprocessing import Pool
|
||||
import urllib.request as req
|
||||
|
||||
|
||||
class HttpDownloader(object):
|
||||
"""
|
||||
HTTP 下载器
|
||||
"""
|
||||
|
||||
def __init__(self, pool=None):
|
||||
self.pool = Pool(16) if not pool else pool
|
||||
|
||||
def download(self, url, dst, chunk_size=1000):
|
||||
"""
|
||||
文件下,自动开启多线程
|
||||
:param url: 下载链接
|
||||
:param dst: 保存路径
|
||||
:param chunk_size: 文件块
|
||||
:return:
|
||||
"""
|
||||
is_support, content_length = HttpDownloader.is_support_range(url)
|
||||
if is_support:
|
||||
# 每个线程下载字节偏移量
|
||||
offset = self.fork(int(content_length), chunk_size)
|
||||
self.__join(offset, url, dst)
|
||||
else:
|
||||
print('无法获取Content-Length,使用单线程下载')
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def is_support_range(url):
|
||||
"""
|
||||
判断是否支持range请求
|
||||
:return:
|
||||
"""
|
||||
wrapper = head(url)
|
||||
header = wrapper.header()
|
||||
h_keys = header.keys()
|
||||
if 'Accept-Ranges' in h_keys and 'Content-Length' in h_keys and header['Accept-Ranges'] != 'none':
|
||||
return True, header['Content-Length']
|
||||
else:
|
||||
return False, 0
|
||||
|
||||
@staticmethod
|
||||
def fork(content_length: int, chunk_size):
|
||||
"""
|
||||
拆分线程
|
||||
:param chunk_size: 文件块大小
|
||||
:param content_length:
|
||||
:return:
|
||||
"""
|
||||
offset = []
|
||||
if content_length <= chunk_size:
|
||||
offset.append((0, content_length))
|
||||
else:
|
||||
for i in range(content_length // chunk_size):
|
||||
start_offset = chunk_size * i + 1
|
||||
end_offset = start_offset - 1 + chunk_size
|
||||
offset.append((0 if i == 0 else start_offset, end_offset))
|
||||
offset.append((chunk_size * (content_length // chunk_size), content_length))
|
||||
return offset
|
||||
|
||||
def __join(self, offset, url, dst):
|
||||
"""
|
||||
多线程下载
|
||||
:param offset:
|
||||
:param url:
|
||||
:param dst:
|
||||
:return:
|
||||
"""
|
||||
|
||||
def download_by_thread(part):
|
||||
_request = req.Request(url=url, headers={
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.70",
|
||||
'Range': f'bytes:{part[0]}-{part[1]}'
|
||||
}, method='GET')
|
||||
response = req.urlopen(_request)
|
||||
with open(dst + f'.{time.time_ns()}', 'wb') as f:
|
||||
f.write(response.read())
|
||||
|
||||
self.pool.map(download_by_thread, offset)
|
||||
self.pool.close()
|
||||
self.pool.join()
|
@ -1,79 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/8/29 23:14
|
||||
# @Author : old tom
|
||||
# @File : http_response.py
|
||||
# @Project : Futool
|
||||
# @Desc : 响应解析
|
||||
|
||||
from http.client import HTTPResponse
|
||||
from http.cookiejar import CookieJar
|
||||
import json
|
||||
|
||||
DEFAULT_ENCODING = 'UTF-8'
|
||||
|
||||
# 响应类型编码
|
||||
RESPONSE_CONTENT_ENCODING = "Content-Encoding"
|
||||
|
||||
# 压缩类型
|
||||
COMPRESS_TYPE = ('gzip', 'deflate', 'br')
|
||||
|
||||
|
||||
class ResponseWrapper(object):
|
||||
|
||||
def __init__(self, response: HTTPResponse, cookie: CookieJar = None):
|
||||
self.resp = response
|
||||
if cookie and len(cookie) > 0:
|
||||
self.cookie = cookie
|
||||
|
||||
def body(self, encoding=DEFAULT_ENCODING):
|
||||
return self.resp.read().decode(encoding)
|
||||
|
||||
def json_body(self, encoding=DEFAULT_ENCODING):
|
||||
return json.loads(self.body(encoding))
|
||||
|
||||
def status(self):
|
||||
return self.resp.status
|
||||
|
||||
def is_ok(self):
|
||||
st_code = self.resp.status
|
||||
return 200 <= st_code <= 300
|
||||
|
||||
def header(self, name=None):
|
||||
return self.resp.getheader(name) if name else self._parse_header_dict()
|
||||
|
||||
def _parse_header_dict(self):
|
||||
headers = self.resp.getheaders()
|
||||
header_dict = {}
|
||||
if headers:
|
||||
for h in headers:
|
||||
header_dict[h[0]] = h[1]
|
||||
return header_dict
|
||||
|
||||
def is_compress(self):
|
||||
"""
|
||||
是否压缩
|
||||
:return:
|
||||
"""
|
||||
return self.compress_type() in COMPRESS_TYPE
|
||||
|
||||
def compress_type(self):
|
||||
"""
|
||||
压缩格式
|
||||
:return:
|
||||
"""
|
||||
header = self.header()
|
||||
if RESPONSE_CONTENT_ENCODING in header.keys():
|
||||
res_content_encoding = header[RESPONSE_CONTENT_ENCODING]
|
||||
return res_content_encoding
|
||||
|
||||
def cookies(self):
|
||||
"""
|
||||
获取cookie
|
||||
:return:
|
||||
"""
|
||||
ck = {}
|
||||
if self.cookie:
|
||||
for item in self.cookie:
|
||||
ck[item.name] = item.value
|
||||
return ck
|
@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2023/4/2 9:07
|
||||
# @Author : old tom
|
||||
# @File : __init__.py.py
|
||||
# @Project : futool
|
||||
# @Desc : excel、word操作相关
|
@ -1 +0,0 @@
|
||||
openpyxl~=3.1.2
|
@ -1,84 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2023/4/2 9:01
|
||||
# @Author : old tom
|
||||
# @File : test_fu_date.py
|
||||
# @Project : futool
|
||||
from unittest import TestCase
|
||||
from futool.core import fu_date
|
||||
|
||||
|
||||
# @Desc :
|
||||
class Test(TestCase):
|
||||
def test_current_year(self):
|
||||
rt = fu_date.current_year()
|
||||
self.assertTrue(rt)
|
||||
|
||||
def test_current_month(self):
|
||||
self.fail()
|
||||
|
||||
def test_current_day(self):
|
||||
self.fail()
|
||||
|
||||
def test_current_date(self):
|
||||
self.fail()
|
||||
|
||||
def test_current_datetime(self):
|
||||
self.fail()
|
||||
|
||||
def test_current_time(self):
|
||||
self.fail()
|
||||
|
||||
def test_current_timestamp(self):
|
||||
self.fail()
|
||||
|
||||
def test_format_datetime_str(self):
|
||||
self.fail()
|
||||
|
||||
def test_format_date_str(self):
|
||||
self.fail()
|
||||
|
||||
def test_datetime_2_second(self):
|
||||
self.fail()
|
||||
|
||||
def test_sec_2_datatime(self):
|
||||
self.fail()
|
||||
|
||||
def test_is_leap(self):
|
||||
self.fail()
|
||||
|
||||
def test_begin_of_week(self):
|
||||
self.fail()
|
||||
|
||||
def test_end_of_week(self):
|
||||
self.fail()
|
||||
|
||||
def test_end_of_month(self):
|
||||
self.fail()
|
||||
|
||||
def test_weekday(self):
|
||||
self.fail()
|
||||
|
||||
def test_age(self):
|
||||
self.fail()
|
||||
|
||||
def test_age_of_now(self):
|
||||
self.fail()
|
||||
|
||||
def test_between(self):
|
||||
self.fail()
|
||||
|
||||
def test_time_offset(self):
|
||||
self.fail()
|
||||
|
||||
def test_is_am(self):
|
||||
self.fail()
|
||||
|
||||
def test_is_pm(self):
|
||||
self.fail()
|
||||
|
||||
def test_next_week(self):
|
||||
self.fail()
|
||||
|
||||
def test_next_month(self):
|
||||
self.fail()
|
@ -1,67 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2023/4/2 9:33
|
||||
# @Author : old tom
|
||||
# @File : test_fu_excel.py
|
||||
# @Project : futool
|
||||
from unittest import TestCase
|
||||
from futool.poi.fu_excel import ExcelReader, SimpleExcelWriter
|
||||
|
||||
ex_reader = ExcelReader(file_path=r'D:\test\test3.xlsx')
|
||||
|
||||
|
||||
# @Desc :
|
||||
class TestExcelReader(TestCase):
|
||||
|
||||
def test_read_sheet(self):
|
||||
sheet = ex_reader.load_sheet('Sheet1')
|
||||
# for row in sheet:
|
||||
# for cell in row:
|
||||
# print(cell.value)
|
||||
for i, row in enumerate(sheet):
|
||||
if i == 0:
|
||||
for cell in row:
|
||||
print(cell.value)
|
||||
|
||||
def test_read_sheet_by_index(self):
|
||||
sheet = ex_reader.load_sheet_by_index(0)
|
||||
for row in sheet:
|
||||
for cell in row:
|
||||
print(cell.value)
|
||||
|
||||
def test_read_row(self):
|
||||
ex_reader.load_sheet('Sheet1')
|
||||
print(ex_reader.read_row(0))
|
||||
|
||||
def test_read_range_row(self):
|
||||
ex_reader.load_sheet('Sheet1')
|
||||
print(ex_reader.read_range_rows(1, 3))
|
||||
|
||||
def test_read_column(self):
|
||||
ex_reader.load_sheet('Sheet1')
|
||||
print(ex_reader.read_column(4))
|
||||
|
||||
def test_read_rows(self):
|
||||
ex_reader.load_sheet('Sheet1')
|
||||
print(ex_reader.read_rows(row_index=[0, 3]))
|
||||
|
||||
def test_read_all(self):
|
||||
ex_reader.load_sheet('Sheet1')
|
||||
print(ex_reader.read_all())
|
||||
|
||||
def test_read_range_column(self):
|
||||
ex_reader.load_sheet('Sheet1')
|
||||
print(ex_reader.read_range_column(1, 4))
|
||||
|
||||
|
||||
class TestExcelWriter(TestCase):
|
||||
def test_write(self):
|
||||
ew = SimpleExcelWriter(r'D:\test\test3.xlsx')
|
||||
# ew.write(head=['序号', '姓名', '年龄', '身份证', '住址'], data=[('1', '张三', '1', '101111', '特特特特特')])
|
||||
ew.write(head=['序号', '姓名', '年龄', '身份证', '住址'], data=self.gen_big_excel())
|
||||
|
||||
def gen_big_excel(self):
|
||||
big_data = []
|
||||
for i in range(0, 999999):
|
||||
big_data.append(('1', '张三', '1', '101111', '特特特特特'))
|
||||
return big_data
|
@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/9/10 10:07
|
||||
# @Author : old tom
|
||||
# @File : test_fu_sys.py
|
||||
# @Project : Futool
|
||||
from unittest import TestCase
|
||||
from futool.system import fu_sys
|
||||
|
||||
|
||||
# @Desc :
|
||||
class Test(TestCase):
|
||||
def test_is_windows(self):
|
||||
rt = fu_sys.is_windows()
|
||||
self.assertTrue(rt)
|
||||
|
||||
def test_is_linux(self):
|
||||
rt = fu_sys.is_linux()
|
||||
self.assertFalse(rt)
|
||||
|
||||
def test_is_unix(self):
|
||||
rt = fu_sys.is_unix()
|
||||
self.assertFalse(rt)
|
||||
|
||||
def test_os_name(self):
|
||||
rt = fu_sys.os_name()
|
||||
self.assertIsNotNone(rt)
|
||||
|
||||
def test_host_name(self):
|
||||
rt = fu_sys.host_name()
|
||||
self.assertIsNotNone(rt)
|
||||
|
||||
def test_sys_user(self):
|
||||
rt = fu_sys.sys_user()
|
||||
self.assertIsNotNone(rt)
|
||||
|
||||
def test_sys_user_dir(self):
|
||||
rt = fu_sys.sys_user_dir()
|
||||
self.assertIsNotNone(rt)
|
||||
|
||||
def test_cpu_info(self):
|
||||
cpu_info = fu_sys.CpuInfo()
|
||||
self.assertIsNotNone(cpu_info.cpu_count())
|
||||
self.assertIsNotNone(cpu_info.cpu_architecture())
|
Loading…
Reference in new issue