Guest User

Untitled

a guest
Oct 18th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. import Control.Exception (SomeException, try)
  4. import Control.Monad (when)
  5. import Data.ByteString.Char8 (ByteString, unpack)
  6. import Data.Either (isRight)
  7. import Network.HTTP.Simple (getResponseBody, httpBS, parseRequest)
  8.  
  9. main :: IO ()
  10. main = do
  11.   let urls = <string of 36 rss feed URLs that I can't paste here>
  12.  mapM_
  13.    ( \url -> do
  14.        putStrLn $ "fetching " ++ url
  15.        res <- try $ fetchUrl url :: IO (Either SomeException ByteString)
  16.        case res of
  17.          Left e -> pure ()
  18.          Right dat -> putStrLn $ "process " ++ show (length (unpack dat) `div` 1024)
  19.    )
  20.    urls
  21.  
  22. fetchUrl :: String -> IO ByteString
  23. fetchUrl url = do
  24.  req <- parseRequest url
  25.  res <- httpBS req >>= pure . getResponseBody
  26.  pure res
Advertisement
Add Comment
Please, Sign In to add comment