summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2014-02-05 02:33:22 -0500
committerBen Boeckel <mathstuf@gmail.com>2014-02-05 02:43:11 -0500
commit7a4219abe3b4885820bece194c7f125274a711c6 (patch)
treee862cf9f8e3fb51fe79e930f51dcc67096244ba4 /src/Plugins
parentc81976467d317dd23489603f255fcf75bb043be9 (diff)
downloadxmobar-7a4219abe3b4885820bece194c7f125274a711c6.tar.gz
xmobar-7a4219abe3b4885820bece194c7f125274a711c6.tar.bz2
Find out whether the weather monitor is likely to block
Uses the HTTP module to do the work rather than curl.
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/Monitors.hs6
-rw-r--r--src/Plugins/Monitors/Weather.hs19
2 files changed, 22 insertions, 3 deletions
diff --git a/src/Plugins/Monitors.hs b/src/Plugins/Monitors.hs
index baeb615..27db417 100644
--- a/src/Plugins/Monitors.hs
+++ b/src/Plugins/Monitors.hs
@@ -19,7 +19,7 @@ module Plugins.Monitors where
import Plugins
-import Plugins.Monitors.Common (runM)
+import Plugins.Monitors.Common (runM, runMD)
import Plugins.Monitors.Weather
import Plugins.Monitors.Net
import Plugins.Monitors.Mem
@@ -40,7 +40,7 @@ import Plugins.Monitors.Wireless
#endif
#ifdef LIBMPD
import Plugins.Monitors.MPD
-import Plugins.Monitors.Common (runMD, runMBD)
+import Plugins.Monitors.Common (runMBD)
#endif
#ifdef ALSA
import Plugins.Monitors.Volume
@@ -136,7 +136,7 @@ instance Exec Monitors where
start (MultiCpu a r) = startMultiCpu a r
start (TopProc a r) = startTop a r
start (TopMem a r) = runM a topMemConfig runTopMem r
- start (Weather s a r) = runM (a ++ [s]) weatherConfig runWeather r
+ start (Weather s a r) = runMD (a ++ [s]) weatherConfig runWeather r weatherReady
start (Thermal z a r) = runM (a ++ [z]) thermalConfig runThermal r
start (ThermalZone z a r) =
runM (a ++ [show z]) thermalZoneConfig runThermalZone r
diff --git a/src/Plugins/Monitors/Weather.hs b/src/Plugins/Monitors/Weather.hs
index bb3d5da..a008453 100644
--- a/src/Plugins/Monitors/Weather.hs
+++ b/src/Plugins/Monitors/Weather.hs
@@ -20,6 +20,7 @@ import Control.Monad (when)
import System.Process
import System.Exit
import System.IO
+import Network.HTTP
import Text.ParserCombinators.Parsec
@@ -129,6 +130,9 @@ parseData =
defUrl :: String
defUrl = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"
+stationUrl :: String -> String
+stationUrl station = defUrl ++ station ++ ".TXT"
+
getData :: String -> IO String
getData url=
do (i,o,e,p) <- runInteractiveCommand ("curl " ++ defUrl ++ url ++ ".TXT")
@@ -156,3 +160,18 @@ runWeather str =
do d <- io $ getData $ head str
i <- io $ runP parseData d
formatWeather i
+
+weatherReady :: [String] -> Monitor Bool
+weatherReady str = do
+ let station = head str
+ request = headRequest (stationUrl station)
+ result <- io $ simpleHTTP request
+ case result of
+ Left _ -> return False
+ Right response -> do
+ case rspCode response of
+ -- Permission or network errors are failures; anything else is
+ -- recoverable.
+ (4, _, _) -> return False
+ (5, _, _) -> return False
+ (_, _, _) -> return True