您的位置:首页 > 其它

一个简单的查询脚本

2016-04-27 18:18 267 查看
#/usr/bin/env python
#coding:utf-8

import re
import MySQLdb
import time

while True:

start_time = raw_input("\033[33m输入开始日期:\033[0m")
m = re.match('\d{4}-\d{2}-\d{2}',start_time)
if m > 0:
end_time = raw_input("\033[33m输入结束日期:\033[0m")
n = re.match('\d{4}-\d{2}-\d{2}',end_time)
if n > 0:
if start_time >= end_time:
print "\033[31m开始日期必须小于结束日期\033[0m"
break
else:
print "\033[32m开始查询\033[0m"
time.sleep(1)
else:
print "\033[34m格式有误!日期格式为:xxxx-xx-xx\033[0m"
break
else:
print "\033[34m格式有误!日期格式为:xxxx-xx-xx\033[0m"
break

conn = MySQLdb.connect("localhost","root","root","aaa")
cur = conn.cursor()
sql = ("select * from ccc where create_time between '%s' and '%s'" % (start_time,end_time))
result = cur.execute(sql)
print "\033[35m查询结果: %s \033[0m" % result
cur.close()
conn.commit()
conn.close()
break
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: