summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRóman Joost <rjoost@redhat.com>2017-08-24 14:32:32 +1000
committerRóman Joost <rjoost@redhat.com>2017-08-24 17:08:13 +1000
commita7bc612666062b5c48efae74054a453334727e91 (patch)
treede92595ae2380afc80928ec72aa2d7cb5b9b7c9b
parentf0c265b3b4359e866673954dbcc5a586c7ae51dd (diff)
downloadxmobar-a7bc612666062b5c48efae74054a453334727e91.tar.gz
xmobar-a7bc612666062b5c48efae74054a453334727e91.tar.bz2
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.
-rw-r--r--readme.md3
-rw-r--r--src/Plugins/Monitors/UVMeter.hs25
-rw-r--r--xmobar.cabal3
3 files changed, 20 insertions, 11 deletions
diff --git a/readme.md b/readme.md
index 64269fe..359ca17 100644
--- a/readme.md
+++ b/readme.md
@@ -158,7 +158,8 @@ Otherwise, you'll need to install them yourself.
Requires the [libXpm] C library.
`with_uvmeter`
-: Enables UVMeter plugin. The plugin shows UV data for Australia.
+: Enables UVMeter plugin. The plugin shows UV data for Australia. Requires
+ `with_conduit` to connect to HTTPS URLs.
`with_weather`
: Support to display weather information. Enables Weather plugin.
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 "<Could not retrieve data>"
+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 "<Could not retrieve data>"
textToXMLDocument :: String -> Either ParseError [XML]
textToXMLDocument = parse document ""
@@ -123,7 +130,7 @@ tag = do
xmlDecl :: Parser XML
xmlDecl = do
- string "<?xml"
+ void $ manyTill anyToken (string "<?xml") -- ignore the byte order mark
decl <- many (noneOf "?>")
string "?>"
return (Decl decl)
diff --git a/xmobar.cabal b/xmobar.cabal
index d03bdb3..9fa4cf2 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -201,6 +201,7 @@ executable xmobar
build-depends: http-conduit, http-types
cpp-options: -DHTTP_CONDUIT
- if flag(with_uvmeter)
+ if flag(with_uvmeter) && flag(with_conduit)
other-modules: Plugins.Monitors.UVMeter
+ build-depends: http-conduit, http-types
cpp-options: -DUVMETER