Open laibinzhi opened 6 years ago
不好意思刚看到,就按照里面的教程来 : https://aplayer.js.org/#/home
`def handle_photo(): '''根据图片的文件名处理成需要的json格式的数据
----------- 最后将data.json文件存到博客的source/photos文件夹下 ''' src_dir, des_dir = "photos/", "min_photos/" file_list = list_img_file(src_dir) print(file_list) list_info = [] for i in range(len(file_list)): filename = file_list[i] date_str, info = filename.split("_") info, _ = info.split(".") date = datetime.strptime(date_str, "%Y-%m-%d") year_month = date_str[0:7] if i == 0: # 处理第一个文件 new_dict = {"date": year_month, "arr":{'year': date.year, 'month': date.month, 'link': [filename], 'text': [info], 'type': ['image'] } } list_info.append(new_dict) elif year_month != list_info[-1]['date']: # 不是最后的一个日期,就新建一个dict new_dict = {"date": year_month, "arr":{'year': date.year, 'month': date.month, 'link': [filename], 'text': [info], 'type': ['image'] } } list_info.append(new_dict) else: # 同一个日期 list_info[-1]['arr']['link'].append(filename) list_info[-1]['arr']['text'].append(info) list_info[-1]['arr']['type'].append('image') list_info.reverse() # 翻转 tmp = bubbleYear(list_info) bubble(tmp) final_dict = {"list": list_info} with open("../deweyliu.github.io/source/photos/data.json","w") as fp: json.dump(final_dict, fp)`
Traceback (most recent call last):
File "tool.py", line 196, in handle_photo() # 将文件处理成json格式,存到博客仓库中 File "tool.py", line 101, in handle_photo datestr, info = filename.split("") ValueError: not enough values to unpack (expected 2, got 1) 很奇怪 开始代码还可以用的 后来handle_photo()这个方法就开始报错 不知道为什么 对python语法还不是太熟悉
是图片命名没有按要求吧,我没有做处理。
如题