From a7bc612666062b5c48efae74054a453334727e91 Mon Sep 17 00:00:00 2001 From: RĂ³man Joost Date: Thu, 24 Aug 2017 14:32:32 +1000 Subject: Fix UVMeter due to changed URL and BOM The URL which exports the real time UV data has changed to an HTTPS address. Since the HTTP package does not support HTTPS URLs, use http-conduit to retrieve the XML document. Unfortunately, the XML documents XML declaration precedes a byte order mark which the previous XML parser was unable to handle. We're simply ignoring the BOM in order to get to the UV values. --- src/Plugins/Monitors/UVMeter.hs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Plugins/Monitors/UVMeter.hs b/src/Plugins/Monitors/UVMeter.hs index b0f5ac3..4d90846 100644 --- a/src/Plugins/Monitors/UVMeter.hs +++ b/src/Plugins/Monitors/UVMeter.hs @@ -18,11 +18,14 @@ module Plugins.Monitors.UVMeter where import Plugins.Monitors.Common import qualified Control.Exception as CE -import Control.Applicative hiding ((<|>),many) -import Network.HTTP +import Network.HTTP.Conduit + (parseRequest, newManager, tlsManagerSettings, httpLbs, + responseBody) +import Data.ByteString.Lazy.Char8 as B import Text.Read (readMaybe) import Text.Parsec import Text.Parsec.String +import Control.Monad (void) uvConfig :: IO MConfig @@ -35,14 +38,18 @@ newtype UvInfo = UV { index :: String } deriving (Show) uvURL :: String -uvURL = "http://www.arpansa.gov.au/uvindex/realtime/xml/uvvalues.xml" +uvURL = "https://uvdata.arpansa.gov.au/xml/uvvalues.xml" getData :: IO String -getData = do - let request = getRequest uvURL - CE.catch (simpleHTTP request >>= getResponseBody) errHandler - where errHandler :: CE.IOException -> IO String - errHandler _ = return "" +getData = + CE.catch (do request <- parseRequest uvURL + manager <- newManager tlsManagerSettings + res <- httpLbs request manager + return $ B.unpack $ responseBody res) + errHandler + where errHandler + :: CE.SomeException -> IO String + errHandler _ = return "" textToXMLDocument :: String -> Either ParseError [XML] textToXMLDocument = parse document "" @@ -123,7 +130,7 @@ tag = do xmlDecl :: Parser XML xmlDecl = do - string "") string "?>" return (Decl decl) -- cgit v1.2.3