nic的gist中的一些辅助函数
nicHelper的Python项目详细描述
帮手
various helpers from nic gist
这里有完整的文档 https://thanakijwanavit.github.io/nicHelper/
from nicHelper.wrappers import add_method
安装
pip install nicHelper
如何使用
方法模块
向类添加
^{pr2}$
hello
这相当于
class A:
def printHello(self):
print('hello')
Dict实用程序
很好地打印了一个dict
只打印dict key的前10个字符,适用于深嵌套dict
from nicHelper.dictUtil import printDict
printDict({'key':'sjfhdkljhafsdlkjhdfaslkjhkljfadshklhfa', 'nestedKey':{'nestedKey2':'938023840843', 'nested3':{'nested4':'hello'}}})
key : sjfhdkljha
nestedKey
nestedKey2 : 9380238408
nested3
nested4 : hello
将所有嵌套的datetime对象更改为timestamp以实现json兼容性
from nicHelper.dictUtil import filterDt
from datetime import datetime
filterDt({'time': {'time2':datetime.now()}, 'hello': 'world'})
{'time': {'time2': 1606887911.36901}, 'hello': 'world'}
异常模块
from nicHelper.exception import errorString
try:
error
except:
print(f'error is \n{errorString()}')
图像实用程序
from nicHelper.images import imageFromUrl, imageToS3, showImgS3, resizeImage
from s3bz.s3bz import S3
## test variables
key = 'testCat.png'
path = '/tmp/testCat.png'
bucket = 'villa-remove-bg-small-output'
url = 'https://sites.google.com/site/funnycatmeawww/_/rsrc/1422326075261/home/6997052-funny-cat.jpg?height=675&width=1200'
调整图像大小
resizeImage(url, 400)
从url加载图像
img = imageFromUrl(url)
type(img)
将图像保存到S3
imageToS3(img, bucket, key)
S3.exist(key,bucket)
显示来自s3的图像
## full test
showImgS3(bucket, key)
秘密
from nicHelper.secrets import getSecret
secret = getSecret(name="removeBg", region='ap-southeast-1')
缩短链接tenxor.sh公司在
from nicHelper.shortenLink import shorten
shorten('https://www.youtube.com/watch?v=fp85zRg2cwg')
标签:
- 项目
推荐PyPI第三方库
hello
这相当于
class A:
def printHello(self):
print('hello')
Dict实用程序
很好地打印了一个dict
只打印dict key的前10个字符,适用于深嵌套dict
from nicHelper.dictUtil import printDict
printDict({'key':'sjfhdkljhafsdlkjhdfaslkjhkljfadshklhfa', 'nestedKey':{'nestedKey2':'938023840843', 'nested3':{'nested4':'hello'}}})
key : sjfhdkljha
nestedKey
nestedKey2 : 9380238408
nested3
nested4 : hello
将所有嵌套的datetime对象更改为timestamp以实现json兼容性
from nicHelper.dictUtil import filterDt
from datetime import datetime
filterDt({'time': {'time2':datetime.now()}, 'hello': 'world'})
{'time': {'time2': 1606887911.36901}, 'hello': 'world'}
异常模块
from nicHelper.exception import errorString
try:
error
except:
print(f'error is \n{errorString()}')
图像实用程序
from nicHelper.images import imageFromUrl, imageToS3, showImgS3, resizeImage
from s3bz.s3bz import S3
## test variables
key = 'testCat.png'
path = '/tmp/testCat.png'
bucket = 'villa-remove-bg-small-output'
url = 'https://sites.google.com/site/funnycatmeawww/_/rsrc/1422326075261/home/6997052-funny-cat.jpg?height=675&width=1200'
调整图像大小
resizeImage(url, 400)
从url加载图像
img = imageFromUrl(url)
type(img)
将图像保存到S3
imageToS3(img, bucket, key)
S3.exist(key,bucket)
显示来自s3的图像
## full test
showImgS3(bucket, key)
秘密
from nicHelper.secrets import getSecret
secret = getSecret(name="removeBg", region='ap-southeast-1')
缩短链接tenxor.sh公司在
from nicHelper.shortenLink import shorten
shorten('https://www.youtube.com/watch?v=fp85zRg2cwg')
- 项目
标签: