python修改typecho全站文章发表日期为某个时间段内的随机时间

技术分享 2019-05-21
# -*- coding: UTF-8 -*-
import MySQLdb as mdb
import time
import random

a1=(2010,12,29,0,0,0,0,0,0)
a2=(2019,5,31,23,59,59,0,0,0)

start=time.mktime(a1)
end=time.mktime(a2)

for i in [7,8,9,10,11,16]:
    t=random.randrange(start,end)
    date_touple=time.localtime(t)
    date=time.strftime("%Y-%m-%d %H:%M:%S",date_touple)?
    timeArray = time.strptime(date, "%Y-%m-%d %H:%M:%S")
    timestamp = int(time.mktime(timeArray))
    print timestamp
    conn = mdb.connect('数据库服务器ip','数据库用户名','数据库密码','数据库名')
    cur = conn.cursor()
    cur.execute("update typecho_contents set created = %s where cid = %s"%(timestamp,i))

评论 (0)

发表评论

最多500字符

验证码

暂无评论

成为第一个评论的人吧!