summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-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")
+ ]