#!/usr/bin/env/python
# -*- coding:utf-8 -*-
import os
import re
import time
import datetime
import random
import hashlib
from ufile import filemanager
from ufile import config as ufile_config
from ufile import logger as img_log
public_key = 'ucloudyunkaopei@outlook.com13615403931104805307'
private_key = 'bcfd5bb66ca527c9be9fd7f3e784fbfc90c4bba5'
addr = '.cn-bj.ufileos.com' # 后缀拼接
ufile_config.set_default(uploadsuffix=addr)
# 公共空间名称
public_bucket = 'zxhx' # 线上正式环境
# public_bucket = 'zxhx-test' # 线上测试环境
image_upload_log = './logs/image_log.txt' # 图片上传日志
img_log.set_log_file(image_upload_log)
# todo 上传图片进程
def upload_img_to_ucloud(param_ucloud):
put_key, localfile = param_ucloud
putufile_handler = filemanager.FileManager(public_key, private_key)
# 普通上传文件至公共空间
ret, resp = putufile_handler.putfile(public_bucket, put_key, localfile, header=None)
assert resp.status_code == 200
def upload_replace_image(filename_root, sid, html):
return_error = {"errcode": 1,
"errmsg": "word图片上传失败。"}
daytime = datetime.datetime.now().strftime('/%Y/%m/%d/')
image_path = filename_root + "/files"
# todo 判断试卷是否含有图片,如果有就替换上传,没有就不处理
local2online_dict = {}
judge_file = os.path.isdir(image_path)
if judge_file: # 可以不用判断
image_number = re.findall(r'{}".format(str(local_images_path_list)))
put_key_list = [] # 线上图片地址
localfile_list = [] # 本地图片地址
rawpic_list = []
online_image_url_list = []
if local_images_path_list:
try:
for i, img in enumerate(local_images_path_list, start=1): # 所有的图片【image1.png,image2.png,。。。】
src_pat2 = re.compile(r'