Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
自用的 python 小工具合集
就是开发过程中常用的一些小方法、小轮子的合集,免去每次用到都得复制
每个人开发思维都不一样,不一定适合其他人
$ pip install angeltools
或者直接下载 duplremover 文件夹到你的项目目录下也行
"""
控制数值区间的方法
"""
from angeltools.MathTool import Scaler
scaler = Scaler()
num = 998
scaler.arctan(x=num, lower_point_x=80, lower_limit=80, upper_limit=100)
# arctan 反正切函数, 用于控制连续变量最大值区间。
# 人话就是用反正切计算比例,确保一个数不超出你锁定的范围
# 要确定一个反正切函数,最少需要确定函数过某一个点,此处称为 锚点
# 变量x
# 锚点的x值
# 锚点的y值
# y值上限
from angeltools.Slavers import Slaves
import time
import random
def do_add(args):
x, y = args
time.sleep(random.randint(1, 2))
return x + y
data = [[x0, y0] for x0, y0 in zip(range(10, 20), range(1, 10))]
ts = time.time()
results = Slaves(workers=10).work(do_add, params_list=data)
te = time.time()
print(results, te - ts)
# Slaves start working: do_add
# [11, 13, 15, 17, 19, 21, 23, 25, 27] 2.007810354232788
from angeltools.Slavers import BigSlaves
import time
import random
def do_add(args):
x, y = args
time.sleep(random.randint(1, 2))
return x + y
data = [[x0, y0] for x0, y0 in zip(range(10, 20), range(1, 10))]
ts = time.time()
results = BigSlaves().work(do_add, params_list=data) # 默认进程数是当前系统可用进程-1
te = time.time()
print(results, te - ts)
# BigSlaves start working: do_add
# [11, 13, 15, 17, 19, 21, 23, 25, 27] 3.0164289474487305
# 由于文件io的延迟性,文件锁不适用于高并发的场景,也不能实现分布式,只适合单机器低速异步进程的隔离
# 优点是不需要数据库或第三方依赖,即开即用
# 高并发可以使用 python-redis-lock
from angeltools.StrTool import FileLock
def do_jobs():
pass
with FileLock(lock_id='test-lock'):
do_jobs()
from angeltools.StrTool import UrlFormat
uf = UrlFormat(url='http://www.baidu.com?page=1&user=me&name=%E5%BC%A0%E4%B8%89')
uf.url_format(params_only=True, unquote_params=True) # {'page': '1', 'user': 'me', 'name': '张三'}
uf.split_url() # {'queries': {'page': '1', 'user': 'me', 'name': '张三'}, 'host': 'www.baidu.com', 'protocol': 'http', 'path': '', 'require_params': '', 'fragment': ''}
uf.make_url(
'http://www.baidu.com',
params_add_dic={'page': '1', 'user': 'me','name': '张三'}
) # 'http://www.baidu.com?page=1&user=me&name=%E5%BC%A0%E4%B8%89'
from angeltools.StrTool import ScrapyXpath
# 包装 scrapy response 的xpath方法,不用每次都 extract 再判断结果,使爬虫更整洁
# 也可以传入由 requests 获取的 response text 和 url,变成 scrapy selector 对象方便提取
import scrapy
div = scrapy.http.HtmlResponse().xpath('//div[@class="xxx"]')
sx = ScrapyXpath(scrapy_selector=div)
sx.xe('./@href') # https://www.xxx.com
sx.xe('.//text()') # ["abc", "efg", ...] 结果有多个时返回列表
# 或者
import requests
url = 'http://www.baidu.com'
html_content = requests.get(url)
sx = ScrapyXpath(url='http://www.baidu.com', html_content=html_content)
sx.xe('./@href') # https://www.xxx.com
sx.xe('.//text()') # ["abc", "efg", ...] 结果有多个时返回列表
from angeltools.ImageTool import image2chars
image2chars(
'/home/Angel.png',
width=30,
k=1.0,
# outfile='/home/测试123.txt',
reverse=True
)
"""
- . -
+ @ # . @ -
# # @ . . + - + - - + . - . + - . @ -
. @ - # = + @ # # @ - + @ # # @ . - @ * # * . @ -
= @ = @ + @ . @ = # * - @ . # # - = @ . . @ -
# @ @ @ @ - + @ @ = @ = . @ . # # = = = . @ -
- @ + - - @ * + @ @ = * @ - * @ . * # . + * . @ -
= * + * - * * + . * @ * @ . * # # - . * .
+ = . + @ .
- # # # +
"""
from angeltools.ImageTool import text2chars
text2chars(
text="ANGEL",
# font_path='/etc/fonts/msyh.ttf',
width=50,
k=0.6,
# outfile='/home/测试123.txt',
chart_list=[' ', '-', '/', '%'],
)
"""
- - - - - - - / / / - - - / / / / / - - -
/ % % % % % % % % - - % % / / / % % - % % / / / / / - - % /
% / / % - % % % % % % - % % - - - % % - - % /
% % % % % % / % - / % - % % / % / / % % % % % % % - % /
- % % % % % % / % % / % % % - % % - - % % % % - - % /
% % - % % - % % / % % - - % % / / / % % % % % % / / / / / - % % / / / / -
- - - - - - - - / / / - - - - - - - - - - - - - - - - -
"""
from angeltools.Db.redis_connector import RedisFdfs
conn = {
"host": '127.0.0.1',
"port": 6379,
"password": None,
}
rdfs = RedisFdfs(
db=1,
connect_params=conn, # redis 连接配置
expire=30 # 缓存过期时间(默认1星期)
)
test_id = rdfs.upload('test data 001')
print(test_id)
# RedisFdfsFile_cceceb50-cc40-11ec-bb8b-adb0630c08c7
test_data = rdfs.get('RedisFdfsFile_cceceb50-cc40-11ec-bb8b-adb0630c08c7')
print(test_data)
# test data 001
# 没有结果或出错的时候返回空字符 ''
test_del = rdfs.delete('RedisFdfsFile_cceceb50-cc40-11ec-bb8b-adb0630c08c7')
print(test_del)
# True
ima2char [image] [-h 查看帮助]
示例:
img2char /home/ABC.png -w 20
输出:
. . .
* = + = + + + - + .
- = - . + = . = .
+ . = . + + . +
+ + . . = - = - - -
- - - + . = . - = . - -
= + + + * . + . + . +
. + + . + - - = .
+ . . + = - + + = + + + .
. . . . .
txt2char [text] [-h 查看帮助]
例如:
txt2char ABC -w 30
输出
. . . . . . . . .
- @ @ + # @ @ @ @ @ * + # @ @ @ * .
* @ @ # # @ * = = # @ * + @ @ = + # @ #
@ # # @ . # @ . @ @ @ @ - # @ +
+ @ = + @ = # @ = + + * @ = - @ # .
# @ . @ @ # @ @ @ @ @ @ . + @ *
. @ @ - . # @ - # @ + - - + @ # - @ *
= @ @ @ @ @ @ * # @ . # @ . . @ @ = @ +
# @ = + + + @ @ # @ + - - + @ @ . * @ * . - @ @ .
- @ # * @ + # @ @ @ @ @ @ + # @ @ @ @ @ +
. + . . + - - + + + + - . + = * = .
FAQs
personal python small tools collection
We found that angeltools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.