Chinaunix首页 | 论坛 | 博客
  • 博客访问: 265554
  • 博文数量: 113
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1044
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-15 16:09
文章分类

全部博文(113)

文章存档

2016年(5)

2015年(108)

我的朋友

分类: Python/Ruby

2015-11-19 02:29:49

通过时间20151119格式,获取表errfile.2015119中id号和  content的内容
注意::
1.文件名为加··(两个反引号)

点击(此处)折叠或打开

  1. import pymysql
  2. import time


  3. #获取时间
  4. def getnum(x):

  5.     now= time.time()
  6.     n = x
  7.     before=[0]*n
  8.     beforeDate=[0]*n
  9.     for i in range(n-1,-1,-1):
  10.         before[i] = now -i * 24 * 3600 #可以改变n 的值计算n天前的
  11.         date = time.strftime("%Y%m%d", time.localtime(now))
  12.         beforeDate[i] = time.strftime("%Y%m%d", time.localtime(before[i]))
  13.         getinfo(beforeDate[i])
  14. #获取content信息
  15. def getinfo(x):
  16.     conn=pymysql.connect(host='xxxxxx',user='radiusquery',passwd='1qaz2wsx',db='RadiusLog')
  17.     cur=conn.cursor()#获取一个游标
  18.     #注意在表名的前后加上反引号
  19.     x="errfile."+x
  20.     Str='SELECT id,content FROM '+'`'+x+'`'
  21.     cur.execute(Str)
  22.     data=cur.fetchall()
  23.     for d in data :
  24.     # #注意int类型需要使用str函数转义
  25.         print(str(d[0])+' '+str(d[1]))

  26.     cur.close()#关闭游标
  27.     conn.close()#释放数据库资源
  28.     
  29. x=input("please input a number:not'(\\n)'")
  30. x=int(x)
  31. getnum(x)

阅读(1727) | 评论(0) | 转发(0) |
0

上一篇:JAVA笔记5

下一篇:php笔记6 mysql

给主人留下些什么吧!~~