博客园图片批量自动上传

import os
s = ' '.join(i for i in os.listdir('.') if i[-3:]=='JPG')
print(s)
os.system("python D:\CmdTools\cnbupd2.py %s"%s)
# cnbupd2.py
import requests
import json
from sys import argv

uploadUrl = 'https://upload.cnblogs.com/imageuploader/processupload?host=www.cnblogs.com'

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
    "cookie": "<>"}
# 类型映射
mimeMapping = {".png": 'image/png', '.gif': 'image/gif',
               '.jpg': 'image/jpeg','.JPG': 'image/jpeg', '.jpeg': 'image/jpeg'}

for i in argv[1:]:
    # 图片地址参数
    imgPath = i

    # 对应的mime
    mime = imgPath[imgPath.rindex("."):]

    file = [
        ("", ("fileName", open(imgPath, "rb"), mimeMapping[mime]))
    ]

    response = requests.post(uploadUrl, headers=headers, files=file)

    data = json.loads(response.text)
    print("![](%s)"%data['message'])
上一篇:html2canvas生成PDF并下载的解决方案


下一篇:JPEG原理快速理解