-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linsen chose to change their api D: #134
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{-# LANGUAGE FlexibleContexts, OverloadedStrings, LambdaCase #-} | ||
{-# LANGUAGE FlexibleContexts, OverloadedStrings, LambdaCase #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
|
||
module Model.Linsen | ||
( | ||
|
@@ -26,7 +27,7 @@ import Data.Text.Lazy ( Text | |
, replace | ||
, strip ) | ||
import Data.Thyme ( parseTime | ||
, defaultTimeLocale ) | ||
, TimeLocale (..) ) | ||
import Data.Thyme.Calendar ( Day ) | ||
import Data.Thyme.Calendar.WeekDate ( weekDate | ||
, _wdDay ) | ||
|
@@ -37,6 +38,44 @@ import Model.Types ( NoMenu(..) | |
, Restaurant ( Restaurant ) ) | ||
import Util ( menusToEitherNoLunch ) | ||
|
||
swedishTimeLocale :: TimeLocale | ||
swedishTimeLocale = TimeLocale | ||
{ wDays = | ||
[ ("Söndag", "Sön") | ||
, ("Måndag", "Mån") | ||
, ("Tisdag", "Tis") | ||
, ("Onsdag", "Ons") | ||
, ("Torsdag", "Tors") | ||
, ("Fredag", "Fre") | ||
, ("Lördag", "Lör") | ||
] | ||
, months = | ||
[ ("Januari", "Jan") | ||
, ("Februari", "Feb") | ||
, ("Mars", "Mar") | ||
, ("April", "Apr") | ||
, ("Maj", "Maj") | ||
, ("Juni", "Jun") | ||
, ("Juli", "Jul") | ||
, ("Augusti", "Aug") | ||
, ("September", "Sep") | ||
, ("Oktober", "Oct") | ||
, ("November", "Nov") | ||
, ("December", "Dec") | ||
] | ||
, amPm = ("fm", "em") | ||
, dateTimeFmt = "%a %f %e %H:%M:%S %Z %Y" | ||
, dateFmt = "%d/%m/%y" | ||
, timeFmt = "%H:%M:%S" | ||
, time12Fmt = "%I:%M:%S %p" | ||
, knownTimeZones = [] | ||
} | ||
|
||
pattern MeatDish, FishDish, VegDish :: Integer | ||
pattern MeatDish = 3 | ||
pattern FishDish = 8 | ||
pattern VegDish = 13 | ||
|
||
fetch | ||
:: (MonadHttp m, MonadIO m, MonadThrow m) | ||
=> m Value -- ^ A JSON response or horrible crash | ||
|
@@ -78,7 +117,10 @@ parse day = | |
[] -> fail "Failed to index into richtext" | ||
(v:_) -> pure v) | ||
>=> (.: "text") | ||
>=> \s -> if pure day == parseTime defaultTimeLocale "%d-%m-%Y" s && length v' >= 9 | ||
>=> \s -> if | ||
pure day == | ||
parseTime swedishTimeLocale "%A %d-%m-%Y" s && | ||
length v' >= 9 | ||
then pure v' | ||
else pure mempty)) | ||
>=> menuParser | ||
|
@@ -92,9 +134,9 @@ parse day = | |
|
||
menuParser :: [Value] -> Parser [Menu] | ||
menuParser = pure . (zip [0 :: Integer ..] >=> \case | ||
(2 ,vs) -> [vs] -- Index of Meat dish | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic indices <3 These are hard to make less magic. :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wrong! :D |
||
(6 ,vs) -> [vs] -- Index of Fish dish | ||
(10,vs) -> [vs] -- Index of Veg dish | ||
(MeatDish, vs) -> [vs] | ||
(FishDish, vs) -> [vs] | ||
(VegDish , vs) -> [vs] | ||
_ -> []) | ||
<=< ap (zipWithM sumFood) tail | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,16 +84,16 @@ main = hspec $ do | |
s1 <- BL.readFile "test/linsen1.json" | ||
testFun | ||
(Right [ Menu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love the updating of the example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I should eat lunch. |
||
(T.pack "Natt Överbakad Högrev.") | ||
(T.pack "Rotfrukter, Timjansky, Persilja, Pommes Chateau.") | ||
(T.pack "Raggmunk.") | ||
(T.pack "Stekt Fläsk, Lingon, Persilja.") | ||
, Menu | ||
(T.pack "Stekt Fisk.") | ||
(T.pack "Remouladsås, Citron, Dill, Picklade Morötter, Rostad Potatis.") | ||
(T.pack "Pocherad Dagens Fångst.") | ||
(T.pack "Sandefjordsås, Brocoli, Brynt Lime, Gräslök Stekt Potatis.") | ||
, Menu | ||
(T.pack "Chana Masala.") | ||
(T.pack "Kikärtor, Grönsaker, Potatis Pakora, Nannbröd, Ris") | ||
(T.pack "Dagens Pasta.") | ||
(T.pack "Tortelioni, Tryffelsås, Baby Spenat, Grana Padano, Roccola.") | ||
]) (L.parse | ||
(fromGregorian 2024 05 31) | ||
(fromGregorian 2024 09 24) | ||
(fromJust $ decode s1)) | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vad är oddsen att de kommer ändra dessa igen...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T-T