packages feed

Finance-Quote-Yahoo 0.6.0 → 0.7.0

raw patch · 2 files changed

+18/−30 lines, 2 filesdep +HTTPdep −curlPVP ok

version bump matches the API change (PVP)

Dependencies added: HTTP

Dependencies removed: curl

API changes (from Hackage documentation)

Files

Finance-Quote-Yahoo.cabal view
@@ -1,10 +1,10 @@ Name:                Finance-Quote-Yahoo-Version:             0.6.0+Version:             0.7.0 Description:         Obtain quote data from finance.yahoo.com Synopsis:	     Obtain quote data from finance.yahoo.com Category:            Web Stability:           experimental-Homepage:            http://www.b7j0c.org/content/haskell-yquote.html+Homepage:            http://www.b7j0c.org/stuff/haskell-yquote.xhtml License:             BSD3 License-file:        LICENSE Author:              brad clawsie@@ -18,5 +18,5 @@     Build-Depends: base >= 3,containers,old-locale   else     Build-Depends: base < 3-  Build-Depends: network,curl,time>=1.1.1+  Build-Depends: network,time>=1.1.1,HTTP>=4000.0.5   Exposed-modules:     Finance.Quote.Yahoo
Finance/Quote/Yahoo.hs view
@@ -5,10 +5,10 @@ which are documented at http:\/\/www.gummy-stuff.org\/Yahoo-data.htm.  The homepage for this module is -http:\/\/www.b7j0c.org\/content\/haskell-yquote.html+http:\/\/www.b7j0c.org\/stuff\/haskell-yquote.xhtml  The license for this module is at-http:\/\/www.b7j0c.org\/content\/license.txt+http:\/\/www.b7j0c.org\/stuff\/license.txt  Since this uses Data.Time.Format, ghc-6.6.1 or greater is required. @@ -73,15 +73,14 @@                             QuoteField,QuoteSymbol,QuoteValue,Quote,                             QuoteCurrency,QuoteFrequency(..),                             HistoricalQuote(..)) where-import qualified Network.Curl as C (curlGetString)-import qualified Network.Curl.Code as CC+import qualified Network.HTTP as H (simpleHTTP,getResponseBody,getRequest)  import qualified Network.URI as U (parseURI,escapeURIString,                                    isUnescapedInURI)  import qualified Data.Time.Calendar as T (Day(..),fromGregorian) import qualified Data.Time.Format as F (formatTime) import qualified System.Locale as L (defaultTimeLocale) import qualified Data.Map as M (fromList,Map(..))-import Data.List (intersperse)+import qualified Data.List as D (intersperse)  {-    License info:@@ -97,17 +96,6 @@ type QuoteCSV = String type Quote = [(QuoteField,QuoteValue)] --- | fetchCSV is a convenience function broken out to isolate HTTP use.-fetchCSV :: QuoteSymbol -> IO (Maybe String)-fetchCSV s = case U.parseURI s of-               Nothing -> error("uri malformed:" ++ s)-               Just uri -> -                   do -                   tryCSV <- C.curlGetString s []-                   case (fst tryCSV) of-                     CC.CurlOK -> return (Just $ snd tryCSV)-                     _ -> return (Nothing)- -- | This is the base uri to get csv quotes. Exported.  baseQuoteURI = "http://download.finance.yahoo.com/d/quotes.csv" :: String @@ -121,6 +109,9 @@     U.escapeURIString U.isUnescapedInURI           $ baseQuoteURI ++ "?s=" ++           (join "+" symbols) ++ "&f=" ++ (concat fields)+             where +               join :: String -> [String] -> String+               join sep = concat . D.intersperse sep  -- | parseQuote will take a list of symbols, a list of fields, and the  -- csv data and return a Data.Map, as described below (see getQuote).@@ -156,10 +147,9 @@ getQuote symbols fields =     do       let req = quoteReq symbols fields-      trycsv <- fetchCSV req-      case trycsv of-        Nothing -> error("no csv returned for " ++ req)-        Just csv -> return $ parseQuote symbols fields csv+      rsp <- H.simpleHTTP (H.getRequest req)+      csv <- H.getResponseBody rsp+      return $ parseQuote symbols fields csv  -- | This is the base uri to get csv historical quote data. Exported. baseHistoricalURI = "http://ichart.finance.yahoo.com/table.csv"@@ -287,16 +277,14 @@     case end > start of       False -> error("start date must be earlier than end date")       True -> do -        trycsv <- fetchCSV (historicalQuoteReq symbol start end freq)-        case trycsv of-          Nothing -> return Nothing-          Just csv -> return $ parseHistorical symbol csv+        let req = historicalQuoteReq symbol start end freq+        rsp <- H.simpleHTTP (H.getRequest req)+        csv <- H.getResponseBody rsp+        return $ parseHistorical symbol csv --- split and join are copies of those from MissingH+-- split copied from missingh split :: Char -> String -> [String] split delim s = if null rest then [token]                              else token : split delim (tail rest)   where (token,rest) = span (/=delim) s -join :: String -> [String] -> String-join sep = concat . intersperse sep