Skip to main content

a python3 components by guolei

Project description

guolei_py3_components

a python3 components by guolei

util

a common util module

from guolei_py3_components import util
util.get_uuid_str(1)
# use util other mehods ...
@util.call_str_to_encrypt("md5")
def encrypt_str():
    return "123456"
print(encrypt_str())
# output e10adc3949ba59abbe56e057f20f883e
  

taobao

a taobao module

from guolei_py3_components import taobao
# get ip data
# @see http://ip.taobao.com/instructions.html
taobao.get_ip_data(ip="")

wechat

a wechat operation class module

from guolei_py3_components import wechat

# init wechat class
wechat_obj = wechat.Wehcat("your appid", "your appsecret")
# get access token
access_token = wechat_obj.get_access_token()
# get js api ticket
js_api_ticket = wechat_obj.get_js_api_ticket(access_token)
# get signatures
signatures = wechat_obj.get_signatures(js_api_ticket="", url="", type="shar1")
# get code url
code_url = wechat_obj.get_code_url(url="")
# get openid
open_id = wechat_obj.get_open_id(code="")   

database

a database module

# get pymysql conn obj
from guolei_py3_components import database
pymysql_conn_config = {
    "host": "localhost",
    "port": "root",
    "user": "luis",
    "passwd": "123456",
    "db": "test",
    "charset": "utf8",
}
pymysql_conn_obj = database.get_pymysql_connection(**pymysql_conn_config)


# call pymysql execute by decorator
pymysql_conn_config = {
    "host": "localhost",
    "port": "root",
    "user": "luis",
    "passwd": "123456",
    "db": "test",
    "charset": "utf8",
}
pymysql_conn_obj = database.get_pymysql_connection(**pymysql_conn_config)


@database.call_pymysql_execute(pymysql_conn_obj)
def pymysql_execute():
    query = "insert into tables...;"
    args = {}
    return query, args


print(pymysql_execute())


# call pymysql find by decorator
from guolei_py3_components import database

pymysql_conn_config = {
    "host": "localhost",
    "port": "root",
    "user": "luis",
    "passwd": "123456",
    "db": "test",
    "charset": "utf8",
}
pymysql_conn_obj = database.get_pymysql_connection(**pymysql_conn_config)


@database.call_pymysql_find(pymysql_conn_obj)
def pymysql_find():
    query = "select * from table;"
    args = {}
    return query, args


print(pymysql_find())


# call pymysql find first by decorator
from guolei_py3_components import database

pymysql_conn_config = {
    "host": "localhost",
    "port": "root",
    "user": "luis",
    "passwd": "123456",
    "db": "test",
    "charset": "utf8",
}
pymysql_conn_obj = database.get_pymysql_connection(**pymysql_conn_config)


@database.call_pymysql_find_first(pymysql_conn_obj)
def pymysql_find_first():
    # You'd better add limit 1 at the end of SQL
    query = "select * from table limit 1;"
    args = {}
    return query, args


print(pymysql_find_first())


# get strictredis conn obj
from guolei_py3_components import database

conn_config = {
    "host": "localhost",
    "port": 6379,
    "db": 0,
    "password": '123456'
}
strictredis_conn_obj = database.get_strictredis_connection(**conn_config)


# call strictredis command by decorator
from guolei_py3_components import database

conn_config = {...},
strictredis_conn_obj = database.get_strictredis_connection(**conn_config)


@call_strictredis_command(strictredis_conn_obj, get)
def strictredis_command():
    return (args), {..kwargs}

logger

from guolei_py3_components import logger
get logging logger obj
logging_logger_obj = logger.get_logging_logger(is_save_file=True)

# call logging logger log by decorator
from guolei_py3_components import logger

logging_logger_obj = logger.get_logging_logger(is_save_file=True)


@logger.call_logging_logger_log(logging_logger_obj, attr, prefix)
def a():
    return ""

mail

from guolei_py3_components.mail import Mail

mail_obj = Mail()
mail_obj.smtp_host = "smtp.exmail.qq.com"
mail_obj.smtp_port = 465
mail_obj.sender_name = "sender<sender@qq.com>"
mail_obj.sender_account = "sender@qq.com"
mail_obj.sender_password = "123456"
mail_obj.to_addresses = ["receiver<receiver@qq.com>"]
mail_obj.cc_addresses = []
mail_obj.bcc_addresses = []
attachments = [
    {
        "name": "attachment.txt",
        "path": "/home/attachment.txt"
    }
]
mail_obj.smtp_ssl_send_mail("subject", "message", attachments)

other

other component developing...

Project details


Download files

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

Source Distribution

guolei_py3_components-1.1.1.tar.gz (10.8 kB view details)

Uploaded Source

File details

Details for the file guolei_py3_components-1.1.1.tar.gz.

File metadata

  • Download URL: guolei_py3_components-1.1.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.1

File hashes

Hashes for guolei_py3_components-1.1.1.tar.gz
Algorithm Hash digest
SHA256 dd635586b2780a22ccd3c2a12e4f02943f1a8897232fc3159bd82e1b9c2b8b6c
MD5 3e532ef91d391ddf768e6219d045b537
BLAKE2b-256 f702f3f046a7197e951d42b4b96a6cb6418935154df73a9a8e68ef6e42e92b21

See more details on using hashes here.

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