From 0dc24691cf63f7348a0e672d81a7e7bc01607b09 Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 4 Jun 2024 18:31:25 +0200 Subject: [PATCH 1/7] Updates --- Dockerfile | 2 +- docker-compose.yml | 2 -- flake.lock | 12 ++++++------ flake.nix | 7 +++++-- mat-chalmers.cabal | 38 +++++++++++++++++++------------------- src/Config.hs | 2 +- src/Model/Wijkanders.hs | 5 +++-- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f7974b..2bd2699 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM haskell:9.4.5 as BIN +FROM haskell:9.6.4 as BIN WORKDIR /app/user COPY *.cabal ./ diff --git a/docker-compose.yml b/docker-compose.yml index 01ceeac..ba79122 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - services: mat: build: . diff --git a/flake.lock b/flake.lock index db382ba..69863cc 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1695360818, - "narHash": "sha256-JlkN3R/SSoMTa+CasbxS1gq+GpGxXQlNZRUh9+LIy/0=", + "lastModified": 1717196966, + "narHash": "sha256-yZKhxVIKd2lsbOqYd5iDoUIwsRZFqE87smE2Vzf6Ck0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e35dcc04a3853da485a396bdd332217d0ac9054f", + "rev": "57610d2f8f0937f39dbd72251e9614b1561942d8", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c537278..66b961e 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ outputs = { self, nixpkgs, flake-utils }: let - ghcVer = "ghc945"; + ghcVer = "ghc964"; makeHaskellOverlay = overlay: final: prev: { haskell = prev.haskell // { packages = prev.haskell.packages // { @@ -52,7 +52,10 @@ packages = p: [ self.packages.${system}.mat ]; withHoogle = true; buildInputs = - [ pkgs.docker ] ++ + [ + pkgs.docker + pkgs.zlib + ] ++ (with haskellPackages; [ haskell-language-server cabal-install diff --git a/mat-chalmers.cabal b/mat-chalmers.cabal index f63c5e3..6a578b7 100644 --- a/mat-chalmers.cabal +++ b/mat-chalmers.cabal @@ -7,7 +7,7 @@ author: Adam Sandberg Eriksson maintainer: adam@sandbergericsson.se category: Web build-type: Simple -Tested-With: GHC ==9.4.5 +Tested-With: GHC ==9.6.4 data-files: static/style.css static/icon.png @@ -18,7 +18,7 @@ data-files: static/fonts/OFL.txt library - default-language: Haskell2010 + default-language: GHC2021 hs-source-dirs: src ghc-options: -Wall -Werror -Wunused-binds -Wunused-imports -Wcompat exposed-modules: Model @@ -34,26 +34,26 @@ library -- versions in the `build-depends` blocks below. build-depends: aeson >= 2.1.2.1 && < 3.0 , attoparsec >= 0.14.4 && < 0.15 - , base >=4.17.1.0 && < 5.0 + , base >=4.18.2.0 && < 5.0 , bytestring >=0.11 && < 0.12 , css-text >= 0.1.3.0 && < 0.2 , exceptions >= 0.10.5 && < 0.11.0 - , heredoc == 0.2.0.0 + , heredoc >= 0.2.0.0 && < 0.3 , logging-effect >= 1.4.0 && <= 2.0 - , microlens-platform >= 0.4.3.3 && < 0.5 - , lucid >= 2 && < 3 - , mtl == 2.2.2 + , microlens-platform >= 0.4.3.5 && < 0.5 + , lucid >= 2.11.1 && < 3 + , mtl >= 2.3.1 && < 2.5 , old-locale == 1.0.0.7 , prettyprinter == 1.7.1 , req >= 3.13 && < 4.0 - , retry == 0.8.1.2 - , safe == 0.3.19 + , retry == 0.9.3.1 + , safe >= 0.3.21 && < 0.4 , tagsoup == 0.14.8 , text >= 2.0 && <= 3.0 - , file-embed >= 0.0.15.0 && < 1.0 + , file-embed >= 0.0.16.0 && < 1.0 , thyme >= 0.4 && <= 0.5 , word8 == 0.1.3 - , extra >= 1.7.10 && <= 1.8 + , extra >= 1.7.16 && <= 1.8 , vector-space >= 0.16 && <0.18 executable mat-chalmers @@ -70,23 +70,23 @@ executable mat-chalmers , mtl , req , prettyprinter - , scotty >= 0.12.1 && < 0.13 - , time >= 1.12 && < 1.13 - , wai-extra >= 3.1.13.0 && < 4.0 + , scotty >= 0.20 && < 0.30 + , time >= 1.12.2 && < 1.13 + , wai-extra >= 3.1.14 && < 4.0 , wai-middleware-static-embedded == 0.1.0.0 - , async >= 2.2.4 && <= 3.0 - default-language: Haskell2010 + , async >= 2.2.5 && <= 3.0 + default-language: GHC2021 Test-Suite test-mat type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: test - default-language: Haskell2010 + default-language: GHC2021 build-depends: base , bytestring , mat-chalmers , aeson >= 2.1.2.1 && < 3.0 - , hspec >= 2.10.10 && < 3.0 + , hspec >= 2.11.8 && < 3.0 , HUnit >= 1.6.2.0 && < 2.0 , text - , thyme >= 0.3.5.5 + , thyme >= 0.4 && <= 0.5 diff --git a/src/Config.hs b/src/Config.hs index 4822482..f107ad1 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -31,4 +31,4 @@ defaultConfig = Config False 14 (1000000 * 60 * 30) 5007 -- TODO: Feel free to bikeshed the function name. reifyConfig :: ([Config -> Config], [String], [String]) -> (Config, [String], [String]) -reifyConfig = (& _1 %~ foldl' (flip id) defaultConfig) +reifyConfig = _1 %~ foldl' (flip id) defaultConfig diff --git a/src/Model/Wijkanders.hs b/src/Model/Wijkanders.hs index d113fb9..070a2da 100644 --- a/src/Model/Wijkanders.hs +++ b/src/Model/Wijkanders.hs @@ -8,6 +8,7 @@ import Control.Arrow ( (***) , (&&&) , (>>>) ) +import Control.Monad ( (<=<) ) import Data.Attoparsec.ByteString.Lazy ( maybeResult , parse , skip @@ -53,7 +54,7 @@ import Util ( menusToEitherNoLunch -- ..and gives them in another order to play nice with the -- YearMonthDay constructor. hasDate :: ByteString -> Maybe (Months, Days) -hasDate = maybeResult . parse ((\d m -> (m, d)) <$> parseDay <*> parseMonth) +hasDate = maybeResult . parse (flip (,) <$> parseDay <*> parseMonth) where parseDay = skipMany (skip (not . W8.isDigit)) *> integerParser parseMonth = string (B8.pack "/") *> integerParser @@ -90,7 +91,7 @@ getWijkanders d = >>> dropWhile (~/= "") >>> removeWhitespaceTags >>> partitions (~== "") - >>> mapMaybe ((maybeTagText =<<) . (`atMay` 1)) + >>> mapMaybe (maybeTagText <=< (`atMay` 1)) >>> map ( BL.break (== W8._colon) >>> ( decodeUtf8With ignore From d70399d19026bded6c001fc55cd4fcb0036bfdfa Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 4 Jun 2024 18:45:31 +0200 Subject: [PATCH 2/7] Workflow change --- .github/workflows/haskell-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index ced3d86..db716f5 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: haskell-actions/setup@v2 with: - ghc-version: '9.4.5' # Exact version of ghc to use + ghc-version: '9.6.4' # Exact version of ghc to use - name: update cabal index run: | From 8e0986a93afee5fa7ebe1c9e54dcfc6707868629 Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 4 Jun 2024 19:40:20 +0200 Subject: [PATCH 3/7] This is cute --- src/Util.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Util.hs b/src/Util.hs index 515d6f1..65fa844 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -27,5 +27,4 @@ menusToEitherNoLunch = \case -- | Remove text tags that only contain whitespace. removeWhitespaceTags :: [Tag ByteString] -> [Tag ByteString] removeWhitespaceTags = - filter (\t -> not (isTagText t) || tagText (not . BL.all W8.isSpace) t) - + filter (or . ([not . isTagText, tagText (not . BL.all W8.isSpace)] <*>) . pure) From e30a20c32df0754e23b35db5c3e6a2706c7119e5 Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 4 Jun 2024 20:16:20 +0200 Subject: [PATCH 4/7] Tehee --- app/Main.hs | 2 +- src/Config.hs | 4 ++-- src/Model.hs | 6 +++--- src/Model/Wijkanders.hs | 28 +++++++++++++++------------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 20aa520..388ffad 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -64,7 +64,7 @@ usage :: IO () usage = putStrLn $ usageInfo "mat-chalmers [OPTION...]" opts main :: IO () -main = (reifyConfig . getOpt Permute opts <$> getArgs) >>= \case +main = (recreateConfig . getOpt Permute opts <$> getArgs) >>= \case (_ , _ , _ : _) -> usage (_ , _ : _, _ ) -> usage (Config { _cHelp = True }, _ , _ ) -> usage diff --git a/src/Config.hs b/src/Config.hs index f107ad1..3738627 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -29,6 +29,6 @@ defaultConfig = Config False 14 (1000000 * 60 * 30) 5007 -- times before it makes sense, so if you're in a hurry, look at the types. -- -- TODO: Feel free to bikeshed the function name. -reifyConfig +recreateConfig :: ([Config -> Config], [String], [String]) -> (Config, [String], [String]) -reifyConfig = _1 %~ foldl' (flip id) defaultConfig +recreateConfig = _1 %~ foldl' (flip id) defaultConfig diff --git a/src/Model.hs b/src/Model.hs index ea9d730..36a0049 100644 --- a/src/Model.hs +++ b/src/Model.hs @@ -94,8 +94,8 @@ update = do if dateNow ^. _localTimeOfDay . _todHour >= nextDayHour then ("Tomorrow", dateNow & _localDay %~ (.+^ 1)) else ("Today", dateNow) - let day' = d ^. _localDay - let karenR = fetchAndCreateRestaurant day' + day' = d ^. _localDay + karenR = fetchAndCreateRestaurant day' rest <- runReq ( defaultHttpConfig { httpConfigRetryPolicy = fibonacciBackoff 30_000_000 <> limitRetries 5 @@ -113,7 +113,7 @@ update = do for_ rest $ \r -> case menu r of Left e -> logMessage =<< timestamp (pretty $ name r <> ": " <> pack (show e)) - _ -> pure () + Right _ -> pure () return (View rest textday d) where diff --git a/src/Model/Wijkanders.hs b/src/Model/Wijkanders.hs index 070a2da..a27a9f6 100644 --- a/src/Model/Wijkanders.hs +++ b/src/Model/Wijkanders.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE OverloadedStrings #-} module Model.Wijkanders ( getWijkanders , hasDate @@ -22,6 +23,7 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BL8 import Data.Maybe ( mapMaybe ) import Data.Text.Encoding.Error ( ignore ) +import Data.Text.Encoding ( encodeUtf8 ) import Data.Text.Lazy.Encoding ( decodeUtf8With ) import Data.Thyme ( Day , Days @@ -57,7 +59,7 @@ hasDate :: ByteString -> Maybe (Months, Days) hasDate = maybeResult . parse (flip (,) <$> parseDay <*> parseMonth) where parseDay = skipMany (skip (not . W8.isDigit)) *> integerParser - parseMonth = string (B8.pack "/") *> integerParser + parseMonth = string (encodeUtf8 "/") *> integerParser integerParser = fmap (read . B8.unpack) (takeWhile1 W8.isDigit) -- | getWijkanders will either give you a list of menus or NoLunch. @@ -74,23 +76,23 @@ getWijkanders d = (((pure . (ymdMonth &&& ymdDay) . view gregorian) d ==) . hasDate) ) >>> takeWhile - (not . tagText - (\s -> BL.isPrefixOf (BL8.pack "Med reservation") s || maybe - False - (> d) - ( hasDate s - >>= ( gregorianValid - . uncurry (YearMonthDay $ ymdYear $ view gregorian d) - ) - ) - ) + (not + . tagText (or + . ([ + BL.isPrefixOf (BL8.pack "Med reservation") + , maybe False (> d) . + (( gregorianValid + . uncurry (YearMonthDay $ ymdYear $ view gregorian d) + ) <=< hasDate) + ] <*>) + . pure) ) -- The heading is of no use to us. >>> drop 1 - >>> dropWhile (~/= "") + >>> dropWhile (~/= ("" :: String)) >>> removeWhitespaceTags - >>> partitions (~== "") + >>> partitions (~== ("" :: String)) >>> mapMaybe (maybeTagText <=< (`atMay` 1)) >>> map ( BL.break (== W8._colon) From 69fca888cb1c208f884f9308e471e4a971090239 Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 4 Jun 2024 20:39:06 +0200 Subject: [PATCH 5/7] Formatting --- src/Model/Wijkanders.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Model/Wijkanders.hs b/src/Model/Wijkanders.hs index a27a9f6..73eb1e8 100644 --- a/src/Model/Wijkanders.hs +++ b/src/Model/Wijkanders.hs @@ -76,16 +76,14 @@ getWijkanders d = (((pure . (ymdMonth &&& ymdDay) . view gregorian) d ==) . hasDate) ) >>> takeWhile - (not - . tagText (or - . ([ - BL.isPrefixOf (BL8.pack "Med reservation") - , maybe False (> d) . - (( gregorianValid - . uncurry (YearMonthDay $ ymdYear $ view gregorian d) - ) <=< hasDate) - ] <*>) - . pure) + (not . tagText + (or . ([ + BL.isPrefixOf (BL8.pack "Med reservation") + , maybe False (> d) . + ( gregorianValid + . uncurry (YearMonthDay $ ymdYear $ view gregorian d) + <=< hasDate) + ] <*>) . pure) ) -- The heading is of no use to us. From 6a8e2491c152985692a0f92be44168cd70fe2c02 Mon Sep 17 00:00:00 2001 From: pingu Date: Wed, 5 Jun 2024 01:06:52 +0200 Subject: [PATCH 6/7] Added another cachix cache to readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5370e7..1316cde 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ nix build # (or nix run) ``` Pro-tip, to get shorter build times, consider using [Cachix] and use -the `jassob` cache: +the `jassob` or `pingu` cache: ``` cachix use jassob # Only needed once +cachix use pingu # Probably more up to date as of 5/6-24 ``` ## Credits From f30658c6c3338c1f9328cf7a073d942b1876f79e Mon Sep 17 00:00:00 2001 From: pingu Date: Wed, 5 Jun 2024 19:25:51 +0200 Subject: [PATCH 7/7] Indentation goes crazy --- src/Model/Wijkanders.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Wijkanders.hs b/src/Model/Wijkanders.hs index 73eb1e8..000e48b 100644 --- a/src/Model/Wijkanders.hs +++ b/src/Model/Wijkanders.hs @@ -78,7 +78,7 @@ getWijkanders d = >>> takeWhile (not . tagText (or . ([ - BL.isPrefixOf (BL8.pack "Med reservation") + BL.isPrefixOf (BL8.pack "Med reservation") , maybe False (> d) . ( gregorianValid . uncurry (YearMonthDay $ ymdYear $ view gregorian d)