django insert data into mysql
2024-09-04 13:09:30
#!/usr/bin/python
# -*- coding:utf-8 -*- # @filename: search
# @author:wwx399777 wuweiji
# @date: 2018/1/25 9:35 import pymysql
import pyecharts
from datetime import datetime
import pandas as pd
import numpy as np
import matplotlib as mpl
import re def connect_mysql(sql, oper_type="select", data_l=None):
conn = pymysql.connect(host='localhost', user="root", password="***",
database="work", port=3306)
cur = conn.cursor()
if oper_type == "insert":
cur.executemany(sql, data_l)
conn.commit()
else:
cur.execute(sql)
result = cur.fetchall()
conn.close()
return result def data_analysis():
sql = """
SELECT p.name, p.email, p.memo from personal_userinfo p
"""
x = connect_mysql(sql)
print(type(x), x)
x = list(x[2])
print(x)
return x data_analysis() def create_list(file_name):
ls = []
if not re.findall(file_name, r".txt"):
file_name += ".txt"
with open(file_name) as f:
for i in f:
name, email, memo = i.strip().split(",")
ls.append([name, email, memo, datetime.utcnow()])
return ls def data_insert():
sql = """
INSERT INTO WORK.personal_userinfo (name, email, memo, date_time) VALUES (%s, %s, %s, %s)
"""
data_l = create_list("person_info")
connect_mysql(sql, oper_type="insert", data_l=data_l) # data_insert()
最新文章
- 分享SQL Server 2012/2014内存数据库,AlwaysOn,参考教材与网上总结
- JVM的GC概述
- Liferay 6.2 改造系列之十四:修改组织的表单内容
- iOS键盘出现时界面跟着往上推
- centOS6.5安装SUN-jdk7
- Java DES 加解密文件
- 对SVM的个人理解
- caption标签,为表格添加标题和摘要
- php转化输入日期为Unix 纪元到当前时间的秒数 日期筛选
- if(!!attr)是什么鬼???
- Java传参
- 【JAVAWEB学习笔记】02_HTML&;CSS
- Python in/not in --- if not/if + for...[if]...构建List+ python的else子句
- vim基本操作
- obj-c编程19:关联对象
- Oracle下查看索引的语句
- 转载:让Windows Server 2012r2 IIS8 ASP.NET 支持10万并发请求
- 1、PHP入门二维数组与循环
- angular.js学习笔记--概念总结
- Sublime 修改快捷键
热门文章
- Windows下findstr命令的使用
- 关于Android ListView组件中android:drawSelectorOnTop含义(转载)
- bzoj 2555: SubString【后缀自动机+LCT】
- poj 2774 Long Long Message【SA】
- bzoj 1207: [HNOI2004]打鼹鼠【dp】
- Luogu P2051[AHOI2009]中国象棋【dp】By cellur925
- STL<;queue>;的使用
- php连接mysql并读取数据
- Magic Numbers CodeForces - 628D
- Math Show CodeForces - 846B