Skip to main content

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)

Metadata

Release files for yourtools 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yourtools 0.6.0
File Size Uploaded Provenance Actions
yourtools-0.6.0.tar.gz 10.1 kB Without provenance Details for yourtools-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yourtools 0.6.0
File Interpreter ABI Platform Actions
yourtools-0.6.0-py3-none-any.whl Python 3 none any Details for yourtools-0.6.0-py3-none-any.whl

Total release size: 21.4 kB

Release files / yourtools-0.6.0.tar.gz

Download URL yourtools-0.6.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
074b7ee453442215ef495660a0acc7a250bb39854b37262102088c41110af401
BLAKE2b-256 checksum
How to use checksums
055a7a751dcc6ce2229b613b700c59eb7d3f7b83696b1ea6adc43c2380f76456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / yourtools-0.6.0-py3-none-any.whl

Download URL yourtools-0.6.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f9a4f4633ff9cc423deab34869fb0df9fc79ab85c5bc6d1b284aadf2cbe3ef1
BLAKE2b-256 checksum
How to use checksums
1c6e83253f9ac9dd2028dce91175133175e571fbe59a508c6815beda04193db9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for yourtools 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page