Skip to main content

发送邮件库

Project description

使用说明

变量环境设置(数据库的链接信息存储在变量环境中)

# 设置环境变量 user 是用户名,password 是密码,192.168.1.10:22484 数据库地址
os.environ['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://user:password@192.168.1.10:22484/'

# 获取环境变量,如果不存在则使用默认值
value = os.environ.get('SQLALCHEMY_DATABASE_URI', 'default_value')
print(value+"DY_DSLP")

1、安装包模块

pip install mjsqltool
pip install --upgrade mjsqltool

2、引入包模块

from mjsqltool import SqlConnect,DataConvert,SqlExecute

SqlConnect

链接数据库,使用完毕后自动关闭

# 数据库名称
db  = 'database'
with SqlConnect(db) as cn:
    .....

DataConvert

数据转换 1、清洗数据 2、数据转SQL

convert = DataConvert()
df = pd.read_exce("jjjj.xlsx")

# 清洗数据
df = convert.convert_to_cleandata(df)

# 转成SQL语句  sql_type:   保存类型 有两个可选参数 'INSERT' 和 'REPLACE'
data = df
table_name = '测试表格'
sql_type='REPLACE'
query = convert.convert_to_sqlstring(data,table_name, sql_type)

SqlExecute

SqlExecute 将数据保存到MySQL SqlExecute 继承了 DataConvert,

from mjsqltool import SqlConnect,DataConvert,SqlExecute
import pandas as pd

with SqlConnect("MJ_DATA") as cn:
    df = pd.read_excel(r"C:\Users\manji\Downloads\联盟订单.xlsx")
    SqlExecute().data_cleanerSave_tosql(df,"测试表格",cn)

SqlExecute().data_cleanerSave_tosql

参数说明

sql_type='INSERT', 
# sql_type='INSERT' 自动忽略重复主键记录 有两个可选参数 'INSERT' 和 'REPLACE'

datalong = None, 
# datalong="only" 为 only时,只写入mysql中存在的数据字段

chunk_size=10000   
# 每次最大写入数据的数据记录,例如90条数据,每次写入10条,则自动拆分成10次写入

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

mjsqltool-1.1.78.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mjsqltool-1.1.78-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file mjsqltool-1.1.78.tar.gz.

File metadata

  • Download URL: mjsqltool-1.1.78.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for mjsqltool-1.1.78.tar.gz
Algorithm Hash digest
SHA256 d71706c0ccd183b73e1efb2697e688250dbe616d3f72de0060af240983254c37
MD5 753bf44d033b47691ae9913777869bd8
BLAKE2b-256 a97923a95515d051e04a92e8910f12b1646a5cd60de71c3b6fef8a446b9361d5

See more details on using hashes here.

File details

Details for the file mjsqltool-1.1.78-py3-none-any.whl.

File metadata

  • Download URL: mjsqltool-1.1.78-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for mjsqltool-1.1.78-py3-none-any.whl
Algorithm Hash digest
SHA256 dafea3e1f642a5b4083d84eabef415711a8987e1c53af947a1791e4b312c968a
MD5 28bc3e3caccdf82451c7bd9960359a70
BLAKE2b-256 2d401b963f6455a77b3aa7ff0d2db3a1839ae1068eb7cb6623f517af16c1e719

See more details on using hashes here.

Supported by

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