For the task of blogging, you can generate Html file locally, then using metaWeblog API to upload them to your blog hosting site. This workflow has following benefits:
- There are many ways to generate Html documents, you can choose which you like.
Especially, you can create clean and readable text file using
markdown
syntax and convert them to Html file. - You can easily backup and reuse the content of your posts.
- You can use version control tool such as
git
to track down the history.
We deliver a Python script blog.py
to upload local Html file to blog site using metaWeblog API.
To use this script, you need to configure it first, change the following two lines of config.py
properly.
serviceUrl, appKey = 'http://www.cnblogs.com/ans42/services/metaweblog.aspx', 'ans42'
usr, passwd = 'ans42', 'xxxx'
After configuration. Now you can:
- list your recent posts:
./blog.py list 12
It will list recent 12
posts, you can omit the number, then it will list 10
posts.
- Upload or Update your post from local Html file:
./blog.py post your-blog.html
This will upload your-blog.html
to your blog site as a new post, or update existing post if you have posted it before.
blog.py
will scan recent 10 posts, when it found a post whose title is the same as your-blog.html
,
then it will think your-blog.html
has been posted already, and update this post instead of create a new one.
For convenience, you can post org-mode
or asciidoc
text file directly.
- Delete a post:
./blog.py delete <post-id>
There are actually two problems need to address:
- Access the metaWeblog API:
blog.py
usexmlrpclib
for this task. - Upload mediaObject(such as Image/Video) and replace their references in locally generated Html:
blog.py
will extract all local image references embed in Html file, then upload them to blog site, replace the local image references using the returned URL. Image files will not be uploaded again if they are not modified.blog.py
think a file has not been modified if itsMD5
has not been changed.