七牛课件重命名

# -*- coding: utf-8 -*-
# flake8: noqa
from qiniu import Auth
from qiniu import BucketManager
import mysql.connector
import time
localtime = time.asctime(time.localtime(time.time()))
current_date = time.strftime(‘%Y-%m-%d’,time.localtime(time.time()))
access_key = ‘WR5JtPxdsdYOgladSBDXZl3idmqjBzqkX5E-UDfG’
secret_key = ‘QOsocxMR2BN9eNZek3gjKeP2j_KznEl-H0JOg5g9’
# 初始化Auth状态
q = Auth(access_key, secret_key)
# 初始化BucketManager
bucket = BucketManager(q)
# 你要测试的空间, 并且这个key在你空间中存在
bucket_name = ‘axx-courseware’

conn = mysql.connector.connect(user=’aixuexidball’, password=’aixuexi_2016dball’,host=’rm-2zefci7s9f4bpy9gt.mysql.rds.aliyuncs.com’, database=’managesystemv1.0′)
cursor = conn.cursor()
cursor.execute(“select DISTINCT(filePath) from coursenote where createTime like ‘” + current_date + “%’ and filePath like ‘kjqn%’;”)

values = cursor.fetchall()
cursor.close()
conn.close()
#print(values)
for val in values:
for real_val in val:
html5_val = real_val.decode()+’/html5.html’
index_val = real_val.decode()+’/index.html’
flash_val = real_val.decode()+’/flash.html’
ret, html5_info = bucket.stat(bucket_name, html5_val)
ret, index_info = bucket.stat(bucket_name, index_val)
ret, flash_info = bucket.stat(bucket_name, flash_val)

if html5_info.status_code != 200 and index_info.status_code == 200 and flash_info.status_code == 200:
ret, info = bucket.move(bucket_name, index_val, bucket_name, html5_val)
if info.status_code == 200:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” rename:”+str(index_val)+”–>”+str(html5_val)+’\n’)
f.close()
else:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” faild:”+str(index_val)+”–>”+str(html5_val)+’\n’)
f.write(localtime+” error:”+info+’\n’)
f.close()

ret, info = bucket.move(bucket_name, flash_val, bucket_name, index_val)
if info.status_code == 200:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” rename:”+str(flash_val)+”–>”+str(index_val)+’\n’)
f.close()
else:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” faild:”+str(flash_val)+”–>”+str(index_val)+’\n’)
f.write(localtime+” error:”+info+’\n’)
f.close()
elif html5_info.status_code != 200 and index_info.status_code != 200 and flash_info.status_code != 200:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” lose:”+html5_val+”&”+index_val+”&”+flash_val+’\n’)
f.close()
elif html5_info.status_code != 200 and index_info.status_code == 200 and flash_info.status_code != 200:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” lose:”+html5_val+”&”+flash_val+’\n’)
f.close()
elif html5_info.status_code != 200 and index_info.status_code != 200 and flash_info.status_code == 200:
f=open(‘rename_kejian.log’, ‘a’)
f.write(localtime+” lose:”+html5_val+”&”+index_val+’\n’)
f.close()

发表评论

电子邮件地址不会被公开。 必填项已用*标注