-------------------------------------------------------------------- -- | -- Module : hackage2hwn -- Copyright : (c) Galois, Inc. 2007 -- License : BSD3 -- -- Maintainer: Don Stewart -- 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 Text.XML.Light import Data.Maybe import Data.List import Data.Char import Text.HTML.Download import Text.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 v = elContent e [es] = [ x | Elem x <- v ] body = elContent es items = map onlyElems [ (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 = let (h:rest) = reverse . takeWhile ( not . isSpace) . reverse . takeWhile (/= ',') $ head [ e | TagText e <- parseTags descr ] (first,last) = break isUpper rest in (h:first ++ " " ++ last) 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