因为大部分文章都是从另一个网站迁移过来的,所以文章的发布时间是集中的,为了解决这个问题,所以有了下面的程序,遍历所有的文章,然后将文章的发布日期修改为随机的发布日期
本文采用Python编程语言,结合pymysql库,实现对文章发布时间的批量修改。以下是具体步骤:
import pymysql, time, random
def get_date():
now = random.randint(1523203200, 1660384792)
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
connect = pymysql.connect(
host='***.***.***.***',
port=3306,
user='***',
password='***',
db='***',
)
cursor = connect.cursor()
select_sql = 'SELECT * FROM blog_article WHERE id > "1"'
cursor.execute(select_sql)
for i in cursor.fetchall():
update_sql = 'update blog_article set pub_date="%s" where id="%s"' % (get_date(), i[0])
cursor.execute(update_sql)
connect.commit()