Skip to content
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

Updates to dependencies, and small touchups in wijkanders #128

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM haskell:9.4.5 as BIN
FROM haskell:9.6.4 as BIN
WORKDIR /app/user
COPY *.cabal ./

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.7'

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to see this removed as it is now obsolete.

services:
mat:
build: .
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 // {
Expand Down Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions mat-chalmers.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ author: Adam Sandberg Eriksson
maintainer: [email protected]
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not enough bikesheding 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tehee ;P

Copy link
Contributor

Choose a reason for hiding this comment

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

Much better!

reifyConfig
recreateConfig
:: ([Config -> Config], [String], [String]) -> (Config, [String], [String])
reifyConfig = (& _1 %~ foldl' (flip id) defaultConfig)
recreateConfig = _1 %~ foldl' (flip id) defaultConfig
6 changes: 3 additions & 3 deletions src/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
29 changes: 15 additions & 14 deletions src/Model/Wijkanders.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
module Model.Wijkanders
( getWijkanders
, hasDate
Expand All @@ -8,6 +9,7 @@ import Control.Arrow ( (***)
, (&&&)
, (>>>)
)
import Control.Monad ( (<=<) )
import Data.Attoparsec.ByteString.Lazy ( maybeResult
, parse
, skip
Expand All @@ -21,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
Expand Down Expand Up @@ -53,10 +56,10 @@ 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
parseMonth = string (encodeUtf8 "/") *> integerParser
integerParser = fmap (read . B8.unpack) (takeWhile1 W8.isDigit)

-- | getWijkanders will either give you a list of menus or NoLunch.
Expand All @@ -74,23 +77,21 @@ getWijkanders d =
)
>>> takeWhile
(not . tagText
(\s -> BL.isPrefixOf (BL8.pack "Med reservation") s || maybe
False
(> d)
( hasDate s
>>= ( gregorianValid
. uncurry (YearMonthDay $ ymdYear $ view gregorian d)
)
)
)
(or . ([
BL.isPrefixOf (BL8.pack "Med reservation")

Choose a reason for hiding this comment

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

Indent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We love indentation

, maybe False (> d) .
( gregorianValid
. uncurry (YearMonthDay $ ymdYear $ view gregorian d)
<=< hasDate)
] <*>) . pure)
)

-- The heading is of no use to us.
>>> drop 1
>>> dropWhile (~/= "<strong>")
>>> dropWhile (~/= ("<strong>" :: String))
>>> removeWhitespaceTags
>>> partitions (~== "<strong>")
>>> mapMaybe ((maybeTagText =<<) . (`atMay` 1))
>>> partitions (~== ("<strong>" :: String))
>>> mapMaybe (maybeTagText <=< (`atMay` 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty!

>>> map
( BL.break (== W8._colon)
>>> ( decodeUtf8With ignore
Expand Down
3 changes: 1 addition & 2 deletions src/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading