Skip to content

Commit

Permalink
Fix week number issue in resto menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Jan 7, 2013
1 parent 455aaf2 commit cc9bf72
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/NumberSix/Handlers/Resto.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module NumberSix.Handlers.Resto
--------------------------------------------------------------------------------
import Control.Monad (mzero)
import Control.Monad.Trans (liftIO)
import Data.Aeson (FromJSON(..), Value(..))
import Data.Aeson (FromJSON (..), Value (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BC
import qualified Data.HashMap.Lazy as HM
Expand All @@ -16,7 +16,8 @@ import Data.Maybe (maybeToList)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Time (UTCTime(..), addDays, formatTime, getCurrentTime)
import Data.Time (UTCTime (..), addDays, formatTime,
getCurrentTime)
import qualified Data.Vector as V
import System.Locale (defaultTimeLocale)

Expand All @@ -36,7 +37,7 @@ data WeekMenu = WeekMenu (M.Map Text [Text]) deriving (Show)
--------------------------------------------------------------------------------
instance FromJSON WeekMenu where
parseJSON (Object o) = return $ WeekMenu $ M.fromListWith (++)
[ (day, [stripMenu name])
[ (day, [T.strip $ stripMenu name])
| (day, Object menu) <- HM.toList o
, Array meats <- maybeToList $ HM.lookup "meat" menu
, Object meat <- V.toList meats
Expand All @@ -59,13 +60,11 @@ resto arg = do
currentTime <- getCurrentTime
let (d, e) = days arg
time = currentTime {utctDay = d `addDays` utctDay currentTime}
week = formatTime defaultTimeLocale "%U" time
week = formatTime defaultTimeLocale "%V" time
day = formatTime defaultTimeLocale "%Y-%m-%d" time
url = "http://zeus.ugent.be/hydra/api/1.0/resto/week/" ++
dropWhile (== '0') week ++ ".json"

putStrLn day
putStrLn url
http (BC.pack url) id >>= \bs -> case parseJsonEither bs of
Left _ -> randomError
Right (WeekMenu m) -> return $ case M.lookup (T.pack day) m of
Expand Down

0 comments on commit cc9bf72

Please sign in to comment.