有时候感觉自己做的工作没有一个方便的工具进行记录,导致做周报或者月报的时候无话可说。公司的事件记录又太复杂,索性自己搞了个简陋的事件记录工具。刚刚学pthon。希望大佬们多提提意见。
[Python] 纯文本查看 复制代码 import pymysql
import pandas as pd
from sqlalchemy import create_engine
#写入操作
def xieru():
conn = pymysql.connect(host='10.90.10.51', user='root', password='Aa123456', db='helpdesk', charset='utf8')
cursor = conn.cursor()
name1=input('用户姓名:')
qu=input('问题:')
yn=input('是否解决:')
x=input('途径(1:微信、2:电话、3:当面):')
if x =='1':
tuj='微信'
elif x=='2':
tuj='电话'
elif x=='3':
tuj='当面'
sql1 = """ insert into helpdesk(姓名,问题,是否解决,途径) value(%s,%s,%s,%s)
"""
cursor.execute (sql1,(name1,qu,yn,tuj))
conn.commit()
conn.close()
print('成功插入', cursor.rowcount, '条数据')
#查询操作
def chaxun():
engine = create_engine('mysql+pymysql://root:Aa123456@10.90.10.51:3306/helpdesk')
sql = '''
select * from helpdesk;
'''
# read_sql_query的两个参数: sql语句, 数据库连接
df = pd.read_sql_query(sql, engine)
print(format(df).ljust(10))
print('Read from table successfully!')
#删除操作
def shanchu():
conn = pymysql.connect(host='10.90.10.51', user='root', password='Aa123456', db='helpdesk', charset='utf8')
cursor = conn.cursor()
name2=input('请输入姓名或者行数:')
sql2="""delete from helpdesk where 姓名=%s"""
sql5 = """delete from helpdesk where ID=%s"""
sql3="""ALTER TABLE `helpdesk` DROP COLUMN `ID`"""
sql4="""ALTER TABLE `helpdesk` ADD `ID` int(10) unsigned NOT NULL AUTO_INCREMENT FIRST,ADD PRIMARY KEY (`ID`), AUTO_INCREMENT = 0 ROW_FORMAT = COMPACT"""
cursor.execute(sql2, (name2))
cursor.execute(sql5, (name2))
print(name2.upper(),'has been delete')
#重新排序
cursor.execute(sql3)
cursor.execute(sql4)
conn.commit()
conn.close()
while True:
print('写入按1', '查询按2', '删除按3')
chose = input('>>>')
if chose == '1':
xieru()
elif chose == '2':
chaxun()
elif chose == '3':
shanchu() |