I've spent a bit of time coding and testing during the Christmas break, and here it is - mtsend.py, a command line tool for Movable Type (SY: Works fine in WordPress as well) written in Python. It uses XML-RPC exported by Movable Type to retrieve posts, edit posts, make new post entry, fix up categories and list recent posts, etc. It is a command line tool, i.e. no graphical user interface, but it is relatively easy to use. It is written in a scripting language called Python, and it currently has only been tested under Python 2.1 on Windows 2000, and Python
2.2/2.3/2.4 on Linux ( Mandrake 8.2/9), Windows 2000 and .
You can download the source code here:
- Download mtsend.py 1.1 (Released on 19 Nov 2005)
What is it?
mtsend.py is a command line tool that utilise Movable Type's XML-RPC interface. It allows its users to edit/post/view/list post entries on a Movable Type site. It takes input from the standard input, and sends output to the stdout, just like all the other well-behaved command line applications. It uses a file format similar to Movable Type's import export format.
Updated: It appears that
mtsend.py also works with WordPress, as WordPress has implemented a compatible XML-RPC interface. In fact I am using this same script everyday since I switched from MT to WP.
Updated 2: There seems to be some timezone issue regarding how WP handles
dateCreated attribute, tested in WP 1.5.
Why command line?
Real man works on text-consoles.
No. It is not true. But I found myself spending most of my day in the front of text console/command prompt. My typical Windows desktop consists 2 of VIM windows and 2 SSH session to other Linux boxes, and half the website I browse everyday is in the excellent text-mode browser w3m. I don't like to fire up Mozilla and open up the Movable Type site just to post an blog entry. Moreover, I have very bad spelling problem, and posting through the web interface does not allow me to check my spellings. Of course I can edit my post in a separate editor, run that external file through a spell checker, and then paste the content into the Movable Type's edit entry page. However, since Movable Type has already exported its interface via XML-RPC, why don't I just write a simple script to post that text file after I've run it through the spell checker? The result becomes mtsend.py.
With a command line tool that can work with pipes and standard IO, it makes posting much easier for me. I can now write up a blog entry in Vi, save the text file, run it through aspell check, and then direct it to mtsend.py to have it posted to my blog site. All under your favourite Unix shell!
These are taken directly from the source code - so just download the latest source and you will have the lot.
Configuration file for mtsend.py is in the style of Windows INI files, which consist of sections and key/value pairs. There are 3 main sections - global, site and blog. Global Section: There is only one key/value in this section, and it is used to note the default blog alias to use if it is not provided on the command line. For example: [global] default=example It shows the default blog alias will be 'example' Site Section: You can have multiple site sections for each Movable Type installation you have access to. The section name will be [site-"site name"]. For example: [site-test] url=http://testdomain.com/mtinstall/mt-xmlrpc.cgi username=foo password=bar encoding=UTF-8 It defines site "test" with the URL to the MovableType's XML-RPC CGI script, and the username/password used to access that site. "encoding" is optional, and defaults to UTF-8. Blog Section: You can have multiple blog sections for each Movable Type blogs you have on the sites you have access to. Blogs are distinguished by their 'alias', which you can select in the command line using -a. The section name for this blog will be [blog-"blog alias"]. For example, [blog-example] site=test blogid=3 Each blog section must have "site", which indicates the site this blog belongs to, so that mtsend would be able to locate site-related information from the configuration file. It also needs the blog ID on that site. To find out all the blog IDs, you can use -B "site name" to print out the list.
When editing or posting via mtsend, the post needs to be in a specific format. The format is very close to Movable Type's import/export format, which is documented here: http://www.movabletype.org/docs/mtmanual_importing.html It consists of a header and body. For example: [header1]: [value1] [header2]: [value2] [header3]: [value3] ----- BODY: .... ----- EXTENDED BODY: .... ----- EXCERPT: .... Extended body and excerpt are optional in a post. Most header elements are optional when you are creating a new post. If they do not provide a value, then the default value configured by Movable Type will be used. These are the header keys/values: TITLE: The title of this post. ALLOW COMMENTS: 0/1 Whether this post allows comments. ALLOW PINGS: 0/1 Whether this post allows trackback pings. CATEGORY: The category associated with this post entry. You can have multiple CATEGORY in the header. The first CATEGORY automatically becomes the primary category, if PRIMARY CATEGORY is not specified. CONVERT BREAKS: 0/1/customised text filter name. Whether the line break will be automatically converted into <br/> and <p/> when posted. It can also be the name of an installed text filer. To get the list of installed text filter, use mtsend.py -T DATE: dd/mm/yyyy HH:MM:SS [AM|PM] The post date. It might not work if you are creating a new post. KEYWORDS: The keywords of your post. PING: The URL to be pinged during posting. You can have multiple PING in the header.
Command Line Argument
Usage: mtsend.py [action] [options] Actions: -B site List all the blogs you can access in [site]. Site has to be in the configuration file. -C Print out a list of existing categories. -E postid Edit an old post. It will read the post entry from the standard input, in Movable Type's import/export format, and then save it back to the server. If the value is '-', then it will try to detect the postid from the input message itself. -G postid Retrieve/get post from the blog. If the value is '-', it will then try to get the most recent blog entry. Retrieved entry will be printed to the standard output. -L num List the most recent [num] posts. -N Posting a new blog. The entry, in the Movable Type import/export format, is read from the standard input. -P postid List out trackback pings to this post. -R postid Rebuild all the static files related to this entry. -T List out the text filters installed on the server. -U filename Upload a file, reading from standard input, to the blog site, with destination filename provided. -V Show version information. Options: -a alias Use "alias" as the blog alias. This script will locate relavent site URL/username/password information using this alias. -c config Load "config" as configuration file, instead of $HOME/.mtsendrc -h Display this help message. -q Decrease verbose level. -v Increase verbose level. Message goes to standard error.
- 1.1 - 19 Nov 2005
- Add SSL support over proxy.
- 1.0 - 26 May 2005
timemodule related fix for Python 2.4.
- Ensure all cells passed to printTable() function are in string-type.
- 0.6.1 - 6 Apr 2004
- Properly handles mt_allow_comments for MT2.6 servers.
- 0.6 - 1 Apr 2004
- Add build-in support for HTTP proxy server, which is detected via environment variable HTTP_PROXY.
- Alternative encoding for XML-RPC packets.
- 0.5 - 14 Oct 2003
- Remove the support of MT2.5. Use the older version of mtsend.py if you need these supports.
- Support KEYWORDS and PING into the header.
- Add new functionalities provided by MT2.6's backend.
- List out trackback pings of a post.
- List out text filters installed.
- Documentation in the source code.
- 0.4 - 10 Mar 2003
- Support the new metaWeblog.newMediaObject() function via mtsend.py -U filename, i.e. you can now upload text/binary files to your MovableType site via mtsend.py!
- Use mt.getRecentPostTitles() function in MT2.6 to save bandwidth.
- Some bug fixes due to some inconsistency between MT2.6 and MT2.5.
- 0.3 - 3 Jan 2003
- Make it to work on Python 2.1. "xmlrpclib" needs to be downloaded separately. It is tested on Python 2.1.2 for Windows.
- 0.2 - 30 Dec 2002
- Fixed a bug in saving the post entry back, where new line characters are stripped.
- 0.1 - 30 Dec 2002
- Initial public version