forked from lix-project/lix
Fix Haskell example
http://nixos.org redirects to https://nixos.org and apparently the HTTP library doesn't follow the redirect, so the output is empty. When defining https in the request it crashes because the library doesn't seem to support https. So this switches the example to a different http library.
This commit is contained in:
parent
4e98f0345c
commit
35129884f9
|
@ -232,22 +232,23 @@ terraform apply
|
||||||
> in a nix-shell shebang.
|
> in a nix-shell shebang.
|
||||||
|
|
||||||
Finally, using the merging of multiple nix-shell shebangs the following
|
Finally, using the merging of multiple nix-shell shebangs the following
|
||||||
Haskell script uses a specific branch of Nixpkgs/NixOS (the 18.03 stable
|
Haskell script uses a specific branch of Nixpkgs/NixOS (the 20.03 stable
|
||||||
branch):
|
branch):
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
#! /usr/bin/env nix-shell
|
#! /usr/bin/env nix-shell
|
||||||
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages (ps: [ps.HTTP ps.tagsoup])"
|
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages (ps: [ps.download-curl ps.tagsoup])"
|
||||||
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-18.03.tar.gz
|
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-20.03.tar.gz
|
||||||
|
|
||||||
import Network.HTTP
|
import Network.Curl.Download
|
||||||
import Text.HTML.TagSoup
|
import Text.HTML.TagSoup
|
||||||
|
import Data.Either
|
||||||
|
import Data.ByteString.Char8 (unpack)
|
||||||
|
|
||||||
-- Fetch nixos.org and print all hrefs.
|
-- Fetch nixos.org and print all hrefs.
|
||||||
main = do
|
main = do
|
||||||
resp <- Network.HTTP.simpleHTTP (getRequest "http://nixos.org/")
|
resp <- openURI "https://nixos.org/"
|
||||||
body <- getResponseBody resp
|
let tags = filter (isTagOpenName "a") $ parseTags $ unpack $ fromRight undefined resp
|
||||||
let tags = filter (isTagOpenName "a") $ parseTags body
|
|
||||||
let tags' = map (fromAttrib "href") tags
|
let tags' = map (fromAttrib "href") tags
|
||||||
mapM_ putStrLn $ filter (/= "") tags'
|
mapM_ putStrLn $ filter (/= "") tags'
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue