def sync_images(folder_path): """ 同步本地文件夹内的图片和cdn上的图片 :param folder_path: 本地图片文件夹路径 :return: """ cdn_cache = [i["key"] for i in qn.list_all(qn.BUCKET_NAME)] for item in cdn_cache: if os.path.exists(os.path.join(WALLPAPER_PATH, item)): continue qn.download(CDN_HOST + item, os.path.join(folder_path, item)) for item in os.listdir(folder_path): file_path = os.path.join(folder_path, item) if is_image(file_path) and item not in cdn_cache: qn.upload_file(item, file_path, "image/jpeg")
def sync_images(folder_path): """ 同步本地文件夹内的图片和cdn上的图片 :param folder_path: 本地图片文件夹路径 :return: """ cdn_cache = [i['key'] for i in qn.list_all(qn.BUCKET_NAME)] for item in cdn_cache: if os.path.exists(os.path.join(WALLPAPER_PATH, item)): continue qn.download(CDN_HOST + item, os.path.join(folder_path, item)) for item in os.listdir(folder_path): file_path = os.path.join(folder_path, item) if is_image(file_path) and item not in cdn_cache: qn.upload_file(item, file_path, 'image/jpeg')
def on_image_change(img_path, event_name): if event_name == "on_deleted": qn.delete(qn.BUCKET_NAME, os.path.split(img_path)[1]) # elif event_name == 'on_modified': # if not is_png(img_path): # upload_path = to_png(img_path, '~upload.tmp') # else: # upload_path = img_path # qn.upload_file(key_from_path(img_path), upload_path, 'image/jpeg') elif event_name == "on_created": if not is_jpeg(img_path): upload_path = to_jpeg(img_path, "~upload.tmp") else: upload_path = img_path qn.upload_file(key_from_path(img_path), upload_path, "image/jpeg") win32_util.set_wallpaper_direct(img_path) # for item in result[0].items(): # print(item[0], item[1]) elif event_name == "on_moved": src_path = img_path[0] dst_path = img_path[1] qn.rename(qn.BUCKET_NAME, key_from_path(src_path), key_from_path(dst_path))
def on_image_change(img_path, event_name): if event_name == 'on_deleted': qn.delete(qn.BUCKET_NAME, os.path.split(img_path)[1]) # elif event_name == 'on_modified': # if not is_png(img_path): # upload_path = to_png(img_path, '~upload.tmp') # else: # upload_path = img_path # qn.upload_file(key_from_path(img_path), upload_path, 'image/jpeg') elif event_name == 'on_created': if not is_jpeg(img_path): upload_path = to_jpeg(img_path, '~upload.tmp') else: upload_path = img_path qn.upload_file(key_from_path(img_path), upload_path, 'image/jpeg') win32_util.set_wallpaper_direct(img_path) # for item in result[0].items(): # print(item[0], item[1]) elif event_name == 'on_moved': src_path = img_path[0] dst_path = img_path[1] qn.rename(qn.BUCKET_NAME, key_from_path(src_path), key_from_path(dst_path))