1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import os import hashlib from PIL import Image
def update_info(path,f,root): image_name=os.path.splitext(f)[0] image_extension=f.split(".")[-1] file=open(path,"rb") image_size=os.path.getsize(path) im=Image.open(path) image_width=im.size[0] image_height=im.size[1] image_date=path.split("\\")[2]+'-'+path.split("\\")[3]+"-"+path.split("\\")[4]+" 12:00:00" image_user_id=1 image_uploader_ip="60.211.13.123" image_md5=hashlib.md5(file.read()).hexdigest() image_original_filename=f i_th=os.path.join(root,image_name+".th."+f.split(".")[-1]) i_md=os.path.join(root,image_name+".md."+f.split(".")[-1]) if(os.path.exists(i_th) and os.path.exists(i_md)): image_chain=7 image_thumb_size=os.path.getsize(i_th) image_medium_size=os.path.getsize(i_md) else: image_chain=5 image_thumb_size=os.path.getsize(i_th) image_medium_size=0 info="INSERT INTO `chv_images` (`image_id`, `image_name`, `image_extension`, `image_size`, `image_width`, `image_height`, `image_date`, `image_date_gmt`, `image_title`, `image_description`, `image_nsfw`, `image_user_id`, `image_album_id`, `image_uploader_ip`, `image_storage_mode`, `image_storage_id`, `image_md5`, `image_source_md5`, `image_original_filename`, `image_original_exifdata`, `image_views`, `image_category_id`, `image_chain`, `image_thumb_size`, `image_medium_size`, `image_expiration_date_gmt`, `image_likes`, `image_is_animated`) VALUES (NULL, '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{5}', '{6}', NULL, '0', '1', NULL, '60.211.13.123', 'datefolder', NULL, '{7}', NULL, '{8}', NULL, '0', NULL, '{9}', '{10}', '{11}', NULL, '0', '0');".format(image_name,image_extension,image_size,image_width,image_height,image_date,image_name[:99],image_md5,f,image_chain,image_thumb_size,image_medium_size) return info
total =0 new_info=open("update_info.txt","w") for root,dirs,files in os.walk(r"D:\images"): for f in files: if f.split(".")[-1] not in ["jpg","png"]: continue if f.split(".")[-2] in ["th","md"]: continue str_info=update_info(os.path.join(root,f),f,root) new_info.write(str_info) new_info.write("\n") total=total+1 print(total)
|