Brool brool (n.) : a low roar; a deep murmur or humming

Haskell To Wordpress (Snippet)

 |  wordpress haskell coding xmlrpc haxr

A small snippet of code that demonstrates calling into a Wordpress XML-RPC server with Haskell and HaxR.

import qualified Data.Map as Map
import Data.Maybe
import Network.XmlRpc.Client
import Network.XmlRpc.Internals

server = ""

-- extract multiple posts from the XML response
extract :: Value -> [Map String Value]
extract xmlresp = 
    let ValueArray rs = xmlresp in
    map (\v -> case v of 
                  ValueStruct vs -> Map.fromList vs
                  _              -> Map.fromList []) rs

getRecentPosts :: Int -> [Char] -> [Char] -> Int -> IO Value
getRecentPosts = remote server "metaWeblog.getRecentPosts"

-- print out the five most recent posts
main = do result <- getRecentPosts 1 "yourname" "yourpass" 5
          let posts = extract result
          mapM_ (\p -> print $ fromJust $ Map.lookup "title" p) posts


Comments are moderated whenever I remember that I have a blog.

Add a comment