A packge of utils or tools keeps Python sweet.
Project description
naotool
🍬A packge of utils or tools keeps Python sweet.
快速上手
pip install naotool
最佳实践
from naotool import deco
@deco.compat_arg_error
def f():
pass
f(1, 2, 3, a=1)
print("ok!")
""" 最佳实践,把一个文件夹内的 .jpg 都重命名为:{md5}.jpg"""
import asyncio
import os
from pathlib import Path
from PIL import Image
from naotool.img.op import img_md5hex
from naotool.img import get
Image.MAX_IMAGE_PIXELS = None
img_dir = Path(r"../../imgs/")
img_name_list = filter(lambda x: x.endswith(".jpg"), os.listdir(str(img_dir)))
path_list = [img_dir / name for name in img_name_list]
async def rename_image(src: Path):
try:
md5 = img_md5hex(await get(str(src)))
new_path = img_dir / f"{md5}{src.suffix}"
os.rename(src, new_path)
except Exception as e:
print(f"Failed to process {src}: {e}")
async def main():
await asyncio.gather(*(rename_image(src) for src in path_list))
asyncio.run(main())
tools
module | example | description |
---|---|---|
img | get() | get 图片 |
deco | @deco.compat_arg_error() | 装饰器 |
httpn | AutoCloseAsyncClient(auto_close_time=3) | 会话自动关闭,严格规范代理 |
exception | NOException | 自定义异常 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
naotool-0.1.10.tar.gz
(6.7 kB
view details)
Built Distribution
File details
Details for the file naotool-0.1.10.tar.gz
.
File metadata
- Download URL: naotool-0.1.10.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78100ae931740f8928d3aad4fc78eac5711d4c8972835ebd719a8056ed256ada |
|
MD5 | 7c11be2bad7c396a1fdd0b173db0be05 |
|
BLAKE2b-256 | 69112075bd621a8f7a869f5ada1b2016d1b4c7fa4750632e995771c9e92afc67 |
File details
Details for the file naotool-0.1.10-py3-none-any.whl
.
File metadata
- Download URL: naotool-0.1.10-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ce587c8f4a5bd60ad8f4671a34dc763345eae67008f6265c549c16535427b89 |
|
MD5 | edcf6e32e18c169813bfe37e494699fb |
|
BLAKE2b-256 | 3336421f9951ca68b544b228cff08969702ef4a770ce8ba0f71b6341f003ca25 |