packages feed

hackage2hwn-0.1: Main.hs

--------------------------------------------------------------------
-- |
-- Module    : hackage2hwn
-- Copyright : (c) Galois, Inc. 2007
-- License   : BSD3
--
-- Maintainer: Don Stewart <dons@galois.com>
-- Stability : provisional
--
-- Pulls the RSS feed from Hackage, pretty prints it in a form suitable for
-- inclusion in the Haskell Weekly News.
--
--------------------------------------------------------------------

module Main (main) where

import XML
import Data.Maybe
import Data.List
import Data.Char

import Data.Html.Download
import Data.Html.TagSoup
import Control.Applicative

url = "http://hackage.haskell.org/packages/archive/recent.rss"

main = mapM_ ppr . render . parseXMLDoc =<< openURL url

-- pretty print in human readable format
ppr (HackageItem a b c) = putStrLn $
    unlines [ "HackageItem"
            , show a
            , show b
            , show c ++ ","
            ]

-- parse xml into hackage items
render Nothing  = error "Unable to download hackage"
render (Just e) = map process items
    where Just v    = elContent e
          [es]      = [ x | Elem x <- v ]
          Just body = elContent es
          items    = map onlyElems [ fromJust (elContent e) | Elem e <- drop 10 body ]


          process [a,b,c,d,e] =
                HackageItem proj
                            author
                            ("[" ++ projurl
                                 ++ " "
                                 ++ takeWhile (not.isSpace) proj
                                 ++ "]: " ++ synopsis ++ "."
                            )
             where
               proj     = strContent a
               projurl  = strContent b
               descr    = strContent e
               author   = reverse . takeWhile ( not . isSpace) . reverse
                                  . takeWhile (/= ',')
                                  $ head [ e |  TagText e <- parseTags descr ]
               synopsis = last [ e |  TagText e <- parseTags descr ]

-- hackage items in the haskell weekly news
data HackageItem = HackageItem Title Author Body
type Title  = String
type Author = String
type Body   = String