Skip to content

Instantly share code, notes, and snippets.

@mkckr0
Created February 16, 2023 14:59
Show Gist options
  • Save mkckr0/8326a988b9077e7aa389d5053322df5d to your computer and use it in GitHub Desktop.
Save mkckr0/8326a988b9077e7aa389d5053322df5d to your computer and use it in GitHub Desktop.
typora upload images to cnblog
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