Skip to content

Commit

Permalink
Made mat-chalmers look at all recipes, not only the first.
Browse files Browse the repository at this point in the history
We only looked at the first recipe for every recipe category, which
made us drop dishes that we in the same recipe category, like the
multiple salad dishes at Classic Salad or the different Linsen dishes.

Should close issue #18 and #24.
  • Loading branch information
Jassob committed Nov 28, 2017
1 parent 97b2925 commit 45dddff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/M/Karen.hs
Expand Up @@ -22,7 +22,7 @@ getKaren weekday name restUrl menuUrl = do
res <- parseMaybe (parseMenuForDay weekday) val
return $ case res of
Nothing -> Left NoLunch
Just l -> Right l
Just l -> Right (concat l)

getKarenToday :: T.Text -> String -> T.Text -> IO Restaurant
getKarenToday name restUrl menuUrl = do
Expand All @@ -32,4 +32,4 @@ getKarenToday name restUrl menuUrl = do
text' <- text
val <- decode text'
(_, l) <- parseMaybe (parseMenus) val
return $ Right l
return $ Right (concat l)
23 changes: 12 additions & 11 deletions src/M/KarenJSON.hs
Expand Up @@ -9,32 +9,33 @@ import Data.Aeson.Types
import qualified Data.Text as TS
import Data.Thyme
import System.Locale (defaultTimeLocale)
import Data.Traversable (traverse)
import Data.Traversable (traverse, for)

import M.Types hiding (name, menu, url)

-- | Get the menu for a specific day. Nothing if there is no menu for
-- that day.
parseMenuForDay :: Day -> Value -> Parser (Maybe [Menu])
parseMenuForDay :: Day -> Value -> Parser (Maybe [[Menu]])
parseMenuForDay day = withObject "top" $ \obj -> do
menuArray <- obj .: "menus"
menus <- traverse parseMenus menuArray
return $ lookup day menus

parseMenus :: Value -> Parser (Day, [Menu])
parseMenus = withObject "days" $ \menu -> do
parseMenus :: Value -> Parser (Day, [[Menu]])
parseMenus = withObject "days" $ \menu -> do
day <- fmap localDay $ menu .: "menuDate"
recips <- menu .: "recipeCategories"
menu' <- traverse parseMenu recips
menu' <- traverse parseMenus' recips
return (day, menu')

parseMenu :: Value -> Parser Menu
parseMenu = withObject "day" $ \obj -> do
parseMenus' :: Value -> Parser [Menu]
parseMenus' = withObject "day" $ \obj -> do
name <- obj .: "name"
(Object recip1:_) <- obj .: "recipes"
(Object what:_) <- recip1 .: "displayNames"
what' <- what .: "displayName"
return $ Menu name what'
recs <- obj .: "recipes"
for recs $ withObject "recipe" $ \rec' -> do
[Object sv, Object eng] <- rec' .: "displayNames"
what' <- sv .: "displayName"
return $ Menu name what'

instance FromJSON LocalTime where
parseJSON = withText "local time" $ \str ->
Expand Down

1 comment on commit 45dddff

@Jassob
Copy link
Contributor Author

@Jassob Jassob commented on 45dddff Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also close issue #19

Please sign in to comment.