summaryrefslogtreecommitdiffstats
path: root/app/Main.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-26 14:08:10 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-26 14:08:10 +0100
commit34c67488c6ebdc19daf7699d424e8257619aa96d (patch)
treeb52e3a38774be185291b5a360194676211f88e34 /app/Main.hs
init
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs63
1 files changed, 63 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
index 0000000..35e675a
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,63 @@
+{-# LANGUAGE BlockArguments #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+
+module Main where
+
+import Conduit
+import Data.Maybe
+import Data.XML.Types
+import Network.HTTP.Conduit
+import Text.Atom.Conduit.Parse
+import Text.Atom.Conduit.Render
+import Text.XML.Stream.Parse
+import Text.XML.Stream.Render
+import Text.XML.Unresolved (elementToEvents)
+
+main :: IO ()
+main = do
+ request <- parseRequest "https://code.nomath.org/abuilder/atom"
+ manager <- newManager tlsManagerSettings
+ runResourceT do
+ response <- http request manager
+ runConduit $
+ ( \feed ->
+ renderAtomFeed feed
+ .| renderBytes def
+ .| printC
+ )
+ . fromJust
+ =<< responseBody response
+ .| parseBytes def
+ .| massage
+ .| atomFeed
+
+massage :: ConduitT Event Event (ResourceT IO) ()
+massage = do
+ await >>= \case
+ Nothing -> pure ()
+ Just e -> do
+ yield e -- BeginDocument
+ await >>= \case
+ Nothing -> pure ()
+ Just e -> do
+ yield e -- <feed>
+ yieldMany (elementToEvents idE)
+ yieldMany (elementToEvents updatedE)
+ mapC id
+ where
+ idE =
+ -- TODO(id)
+ Element
+ "{http://www.w3.org/2005/Atom}id"
+ []
+ [ NodeContent (ContentText "TODO")
+ ]
+ updatedE =
+ -- TODO(updated)
+ Element
+ "{http://www.w3.org/2005/Atom}updated"
+ []
+ [ NodeContent (ContentText "1970-01-01T00:00:00Z")
+ ]