Re: State of MetaWeblog API?
Garth Corral <[email protected]> Wed, 21 Jul 2004 00:42:33 -0700
| Newsgroups | gmane.comp.web.syncato.general |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail-15-419404081
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
On Jul 19, 2004, at 7:34 AM, darryl wrote:
> Patches appreciated !
>
Okay, here's a patch against the head in CVS that implements
mt_setPostCategories(). The rest of it is untouched save for a couple
of nits that I fixed. Also, config.xml in the tree should probably be
changed to set <category-root-element> correctly for this to work from
a checkout.
This is not well tested at all and it's not likely to get a lot of
testing by me but it allows me to do what I wanted with NetNewsWire
which is create a new posting with categories. The weblog in NNW needs
to be configured as a Movable Type system. I'll be happy to fix any
bugs in this but as I said, I'm not likely to find them myself.
Not related to the syncato implementation, it's kind of an unpleasant
little protocol. Not very flexible and a lot of overhead for not much
gain over GET/POST and friends. I guess the gain comes from it being
in fairly widespread use. Still.
--Apple-Mail-15-419404081
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="metaweblog_patch.txt"
Content-Disposition: attachment;
filename=metaweblog_patch.txt
Index: MetaWeblog.py
===================================================================
RCS file: /cvsroot/syncato/Syncato/dist/servlets/open/MetaWeblog.py,v
retrieving revision 1.6
diff -u -r1.6 MetaWeblog.py
--- MetaWeblog.py 25 Nov 2003 06:00:54 -0000 1.6
+++ MetaWeblog.py 21 Jul 2004 07:03:07 -0000
@@ -142,7 +142,7 @@
def metaWeblog_deletePost(self, appkey, postID, username, password, publish):
client = WeblogClient.WeblogClient(self.host, self.baseURL, username, password)
- print "post to delete:", postID
+ #print "post to delete:", postID
result = client.deletePost(postID)
return result.reason
@@ -160,7 +160,7 @@
result = client.runRequest("GET", self.baseURL + query)
categoryXML = libxml2.parseDoc(result.read())
- results = categoryXML.xpathEval('//category')
+ results = categoryXML.xpathEval('//' + itemRoot)
#print results
for item in results:
category = {}
@@ -188,7 +188,7 @@
result = client.runRequest("GET", self.baseURL + query)
categoryXML = libxml2.parseDoc(result.read())
- results = categoryXML.xpathEval('//category')
+ results = categoryXML.xpathEval('//' + itemRoot)
#print results
for item in results:
category = {}
@@ -206,13 +206,13 @@
def mt_getPostCategories(self, postID, username, password):
client = WeblogClient.WeblogClient(self.host, self.baseURL, username, password)
- print postID
+ #print postID
result = client.getPost(postID)
- print result
+ #print result
categories = result['categories']
finalResult = []
for category in categories:
- print category
+ #print category
rec = {}
rec['categoryId'] = category
rec['categoryName'] = category
@@ -221,8 +221,39 @@
return finalResult
- def mt_setPostCategories(self, postID, username, password, categories=[]):
- return Boolean(1)
+ def mt_setPostCategories(self, postID, username, password, categories):
+ """
+ Sets the categories for a post.
+
+ The categories parameter is passed as a list of dicts containing a
+ categoryId and isPrimary field. Use of isPrimary to set the primary
+ category is optional in the MT API and is ignored by Syncato.
+ """
+
+ categoryMap = {} # Category ID to name map.
+ categoryNames = []
+
+ client = WeblogClient.WeblogClient(self.host, self.baseURL,
+ username, password)
+
+ # Get the categories for our database and map the names to their ID.
+ # It'd be nice to cache this but I have no idea how to invalidate it.
+ for category in self.mt_getCategoryList(None, username, password):
+ categoryMap[category['categoryId']] = category['categoryName']
+
+ # The MT API passes in category IDs but we need to pass names to
+ # WeblogClient.editPost(). Look up the names in our map from above.
+ for category in categories:
+ try:
+ categoryNames.append(categoryMap[category['categoryId']])
+ except KeyError:
+ pass
+
+ post = client.getPost(postID)
+ result = client.editPost(postID, post['title'],
+ post['body'], categoryNames)
+
+ return result.reason
def publishPost(self, postID, username, password):
# We don't support this concept so we just return true.
--Apple-Mail-15-419404081--
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click