module Main where {- This program shows how to use the Text.Yahoo.ContextSearch module to send context queries to Yahoo. Query strings are read in on stdin, sent to Yahoo, and the results displayed on stdout. Using the WebSearch module is similar. -} import System.Exit (exitWith, ExitCode(..)) import Text.Yahoo.ContextSearch (contextSearch, contextQuery) import Text.Yahoo.Types -- build a query with the defaults buildQuery queryString = contextQuery "YahooDemo" queryString "Haskell" 3 showResult r = "Title: " ++ show (title r) ++ "\n" showResultSet rs = "Num. Results Available: " ++ show (totalResultsAvailable rs) ++ "\n" ++ "Num. Results Returned: " ++ show (totalResultsReturned rs) ++ "\n" ++ concatMap showResult (results rs) doQuery q = do rs <- contextSearch q case rs of (Left e) -> return $ "Error: " ++ fst e (Right rs') -> return $ showResultSet rs' main = forever $ do l <- getLine case l of (':':'q':cs) -> exitWith ExitSuccess q -> do r <- (doQuery . buildQuery) q putStrLn r forever a = a >> forever a