ブログにXML-RPC APIで、複数のファイルをアップロードするRubyスクリプト:Goodpicpythonは楽でいいや。I love python!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, glob
import base64
import mimetypes
import xmlrpclib
if len(sys.argv) < 6:
print "usage: url blogid username password path [files ... or directory]"
sys.exit()
metaWeblog = xmlrpclib.Server(sys.argv[1]).metaWeblog
for arg in sys.argv[6:]:
if os.path.isdir(arg): arg = os.path.join(arg,'*')
for f in glob.glob(arg):
print metaWeblog.newMediaObject(
sys.argv[2], # blogid
sys.argv[3], # username
sys.argv[4], # password
{
'name' : "%s/%s" % (sys.argv[5], os.path.basename(f)),
'type' : mimetypes.guess_type(f)[0] or 'application/octet-stream',
'bits' : xmlrpclib.Binary(open(f, "rb").read())
})
使い方は
upload.py http://your.blog.server/xmlrpc your-blog-id username password upload-directory [local files or directory]
AWSWORD:python: