Skip to content

Commit

Permalink
Based on some comments of Ekeroot
Browse files Browse the repository at this point in the history
  • Loading branch information
The1Penguin committed May 30, 2024
1 parent 30700ea commit 6bfd82e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Model/Linsen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Data.Text.Lazy ( Text
, replace
, strip )
import Data.Thyme.Calendar ( Day )
import Lens.Micro.Platform ( (^.) )
import Network.HTTP.Req
import Model.Types ( NoMenu(..)
, Menu(..)
Expand All @@ -36,7 +37,8 @@ import Model.Types ( NoMenu(..)
)
)
import Util ( menusToEitherNoLunch )
import Data.Thyme.Calendar.WeekDate ( toWeekDate )
import Data.Thyme.Calendar.WeekDate ( weekDate
, _wdDay)

fetch
:: (MonadHttp m, MonadIO m, MonadThrow m)
Expand All @@ -59,7 +61,7 @@ parse day =
(parseEither
( withObject "Parse meals"
$ (.: "docs")
>=> (pure . (!! (6 - (\(_,_,a) -> a) (toWeekDate day))))
>=> (pure . (!! (6 - (day ^. weekDate . _wdDay))))

This comment has been minimized.

Copy link
@Rembane

Rembane May 30, 2024

Contributor

Legendary!

>=> (.: "richText")
>=> (.: "root")
>=> (.: "children")
Expand All @@ -74,9 +76,9 @@ parse day =

menuParser :: [Value] -> Parser [Menu]
menuParser = pure . (zip [0 :: Integer ..] >=> \case
(2 ,vs) -> [vs]
(6 ,vs) -> [vs]
(10,vs) -> [vs]
(2 ,vs) -> [vs] -- Index of Meat dish
(6 ,vs) -> [vs] -- Index of Fish dish
(10,vs) -> [vs] -- Index of Veg dish
_ -> []) <=< ap (zipWithM sumFood) tail

sumFood :: Value -> Value -> Parser Menu
Expand All @@ -87,8 +89,8 @@ parse day =
$ (.: "children")
>=> \case
[] -> pure mempty
vs -> last vs .: "text"
<&> strip . replace "/ " ", "
vs -> strip . replace "/ " ", "
<$> last vs .: "text"

fetchAndCreateLinsen
:: (MonadHttp m, MonadIO m, MonadThrow m)
Expand Down

0 comments on commit 6bfd82e

Please sign in to comment.