Skip to main content

tmtool

Project description

tm-pip-tools

工具集合

上传pypi

python setup.py bdist_wheel
twine upload dist/*

安装(Python 版本>=3.8.0)

pip install --upgrade tmtoolP

使用

发送邮件

from tmtool.tools import Tool
tool = Tool()

tool.mail_from_user_host = '发件地址host'
tool.mail_from_user = '发件人邮箱号'
tool.mail_from_user_pwd = '发件人密码'

tool.send_mail_msg(to_user='收件人邮箱地址(这里是列表,可填写多个)', title='邮件标题', content='邮件内容')

格式转换

tool.json_dumps({"test": "python字典"})  # 字典转字符串
tool.json_loads('{"test": "python字典"}')  # 字符串转字典

tool.xml_to_dict('<xml><data>字符串</data></xml>')  # xml转字典
tool.dict_to_xml({"test": "python字典"})  # 字典转xml

企业微信机器人

from tmtool.tools import Tool
tool = Tool()

tool.qy_wechat_token = '7fdda192-cfcb-4eb5-87a5-b341574562d5'

# @ 所有人
tool.send_qy_wechat_msg("自测内容,忽略!", at_all=['@all'])
# @ 指定人
tool.send_qy_wechat_msg("自测内容,忽略!", at_all=['18600967174'])
# @ 指定多人
tool.send_qy_wechat_msg("自测内容,忽略!", at_all=['18600967174', '15210205078'])

时间转换

tool.time_stamp()       # 10位秒级时间戳
tool.time_stamp('ms')   # 13位毫秒时间戳

tool.get_now_time()     # 获取当前时间

tool.date_to_time_stamp('2022-03-25 00:00:00')  # 时间字符串转为时间戳
tool.time_stamp_to_date(1732312234)             # 时间戳转为时间字符串

随机数据

tool.random_phone()  # 随机手机号
tool.random_name()  # 随机姓名
tool.random_ssn()  # 随机身份证

tool.random_string(16)  # 随机位数的字符串
tool.random_number(8)  # 随机位数的数字

http请求

tool.http_client(url='', data={}, method='GET')  # get请求

tool.http_client(url='', data={}, method='POST')  # post请求 -(暂无header #TODO) 

tool.trans_data_to_url(url='接口地址', data={})  # 把参数拼接到url上

MySQL数据库相关

# 生成sql语句

from tmtool.TmMySQL import SqlStr

tmsql = SqlStr()

# 查询语句 -> target不传时,为全部字段,即*,where={'key':'value'}
tmsql.select_sql_str(table='user', where={'id': 1, 'nick_name': '测试用户'})

# 查询语句 -> target=[i1,i2,i3]时,为相应表字段
tmsql.select_sql_str(table='user', target=['username', 'password'], where={'id': 1, 'nick_name': '测试用户'})

# TODO

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tmtoolP-0.1.32-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page