一个简单的查询脚本

Posted on 2016-04-27 18:18  心在北方  阅读(227)  评论(0编辑  收藏  举报

#/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

Copyright © 2024 心在北方
Powered by .NET 9.0 on Kubernetes