Skip to content

Commit

Permalink
Now doesn't show food at linsen if it is not the same week
Browse files Browse the repository at this point in the history
  • Loading branch information
The1Penguin committed Jun 26, 2024
1 parent 06abc19 commit d61648a
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/Model/Linsen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,34 @@ where
import Control.Monad ( (>=>)
, (<=<)
, zipWithM
, ap
)
, ap )
import Control.Monad.Catch ( MonadThrow )
import Control.Monad.IO.Class ( MonadIO )
import Data.Aeson ( (.:)
, withObject
, Value
)
, Value )
import Data.Aeson.Types ( Parser
, parseEither
)
, parseEither )
import Data.Bifunctor ( first )
import qualified Data.ByteString.Lazy.Char8 as BL8
import Data.Functor ( (<&>) )
import Data.List.Extra ( (!?) )
import Data.Text.Lazy ( Text
, replace
, strip )
import Data.Thyme ( parseTime
, defaultTimeLocale )
import Data.Thyme.Calendar ( Day )
import Data.Thyme.Calendar.WeekDate ( weekDate
, _wdDay, _wdWeek)
import Lens.Micro.Platform ( (^.) )
import Network.HTTP.Req
import Model.Types ( NoMenu(..)
, Menu(..)
, Restaurant
( Restaurant
)
)
import Util ( menusToEitherNoLunch )
import Data.Thyme.Calendar.WeekDate ( weekDate
, _wdDay)
, Restaurant ( Restaurant ) )
import Safe ( headMay )
import Util ( menusToEitherNoLunch
, (^.^) )

fetch
:: (MonadHttp m, MonadIO m, MonadThrow m)
Expand Down Expand Up @@ -72,6 +70,19 @@ parse day =
>=> (.: "richText")
>=> (.: "root")
>=> (.: "children")
>=> (\v' ->
withObject "asd" (
(.: "children")
>=> (\case
Nothing -> fail "Failed to index into food"
Just v -> pure v) . headMay
>=> (.: "text")
>=> pure . (== pure (day ^. weekDate . _wdWeek)) .
(parseTime defaultTimeLocale "V. %U" >=> (^.^ _wdWeek))
>=> \case
True -> pure v'
False -> pure [])
(head v'))
>=> menuParser . (\v' -> if length v' >= 9 then v' else mempty)
)
)
Expand Down

0 comments on commit d61648a

Please sign in to comment.