Created
February 16, 2023 14:59
-
-
Save mkckr0/8326a988b9077e7aa389d5053322df5d to your computer and use it in GitHub Desktop.
typora upload images to cnblog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import sys | |
from xmlrpc.client import Binary, ServerProxy | |
cwd = os.path.dirname(__file__) | |
img_list = sys.argv[1:] | |
with open(f"{cwd}/config.json", 'r', encoding='utf8') as ifile: | |
config = json.load(ifile) | |
appKey = '' | |
username = config['username'] | |
password = config['password'] | |
with ServerProxy(config['rpc_uri']) as proxy: | |
res = proxy.blogger.getUsersBlogs(appKey, username, password) | |
blogid = res[0]['blogid'] | |
for img in img_list: | |
file = {} | |
with open(img, 'rb') as ifile: | |
file['bits'] = Binary(ifile.read()) | |
file['name'] = os.path.basename(img) | |
res = proxy.metaWeblog.newMediaObject(blogid, username, password, file) | |
print(res['url']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment