Python helper tools
Project description
Python tools
Installation
pip3 uninstall yourtools
pip3 install yourtools
Table of Contents
- WeChat
- send_msg 发送应用消息
- upload_media 上传临时素材文件到企微,并返回media_id
- MySQL
- query 执行普通查询SQL
- execute 执行DML SQL
- Hive
- query 执行普通查询SQL
- exec_ddl_sql 执行DML SQL
Example
1、MySQL
from yourtools import MySQL
def test_mysql():
dbconfg = {
'host': '172.0.0.1',
'port': 3306,
'username': 'root',
'password': '123456',
'db': 'test',
'charset': 'utf8'
}
server = SSHTunnelForwarder(
('跳板机服务器IP', 45535),
ssh_username='root',
ssh_password='123456',
remote_bind_address=('远程数据库IP', 3366),
local_bind_address=('127.0.0.1', 3366)
)
# 不使用跳板机
mysql = MySQL(dbconfg)
# 使用跳板机,需要传递一个SSHTunnelForwarder对象
mysql = MySQL(dbconfg,ssh_tunnel=server)
# query data
result = mysql.query("select * from users")
print(result)
# dml sql
result = mysql.execute("insert into users(name,birthday,ts) values('灭霸2','2022-11-01 16:00:00','2022-11-01 16:00:00') ")
2、Hive
from yourtools import Hive
hive_connection = {
'host': '127.0.0.1',
'port': 10000,
'db': 'ods',
'username': '',
'auth': 'NOSASL'
}
hive = Hive(hive_connection)
hive_sql="""
select * from ods.ods_user
"""
rows = hive.query(hive_sql)
print(rows)
3、WeChat
from yourtools import WeChat
# WeChat(corpid,Secret,AgentId)
qw = WeChat("asdg234234", "OINFSokasdIOKflsafdaOOKFD", 1000000)
data = {
"touser": "198297694527839423",
"toparty": "",
"totag": "",
"msgtype": "text",
"agentid": 1000000,
"text": {
"content": "你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>,聪明避开排队。"
},
"safe": 0,
"enable_id_trans": 0,
"enable_duplicate_check": 0,
"duplicate_check_interval": 1800
}
send_statu = qw.send_msg(data)
print(send_statu)
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
yourtools-0.6.0.tar.gz
(10.1 kB
view details)
Built Distribution
yourtools-0.6.0-py3-none-any.whl
(11.3 kB
view details)
File details
Details for the file yourtools-0.6.0.tar.gz
.
File metadata
- Download URL: yourtools-0.6.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 074b7ee453442215ef495660a0acc7a250bb39854b37262102088c41110af401 |
|
MD5 | c40e51826069896a9ddc6b878f378455 |
|
BLAKE2b-256 | 055a7a751dcc6ce2229b613b700c59eb7d3f7b83696b1ea6adc43c2380f76456 |
File details
Details for the file yourtools-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: yourtools-0.6.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f9a4f4633ff9cc423deab34869fb0df9fc79ab85c5bc6d1b284aadf2cbe3ef1 |
|
MD5 | 939f13c54645c85b6baf5866ed911d6c |
|
BLAKE2b-256 | 1c6e83253f9ac9dd2028dce91175133175e571fbe59a508c6815beda04193db9 |