1
0
Fork 0

Improve rssfeeds

This commit is contained in:
Malte 2023-01-31 02:15:51 +01:00
parent a91356208a
commit 57f0140ea3
8 changed files with 53 additions and 55 deletions

View file

@ -45,8 +45,8 @@
source = ./wizards-dialog;
};
logfeed = cleanCabalPackage {
name = "logfeed";
source = ./logfeed;
name = "rssfeeds";
source = ./rssfeeds;
};
kassandra = cleanCabalPackage {
name = "kassandra";

View file

@ -1,50 +0,0 @@
module Main where
import Data.String.Interpolate (i)
import Data.Text qualified as Text
import Data.Time (UTCTime)
import Data.Time qualified as Time
import Relude hiding (
intercalate,
zip,
)
import System.Environment ()
import System.FilePattern.Directory (getDirectoryFiles)
import Text.Atom.Feed
import Text.Atom.Feed.Export (textFeed)
import Witch
timestamp :: UTCTime -> Text
timestamp = into . Time.formatTime Time.defaultTimeLocale "%Y-%m-%d %H:%M"
main :: IO ()
main = do
[out_file, dir] <- getArgs
now <- Time.getCurrentTime
new_files <- getDirectoryFiles dir [Time.formatTime Time.defaultTimeLocale "%Y-%m-%d-*/index.html" now]
let entries =
fmap
( ( \file_name ->
let
folder_name =
Text.dropEnd 11 file_name
in
( nullEntry
folder_name
(TextString [i|mastodon digest #{Text.drop 11 folder_name}|])
(timestamp now)
)
{ entryLinks = [nullLink [i|http://hera.vpn.m-0.eu:8842/mastodon/#{file_name}|]]
}
)
. into
)
new_files
feed =
nullFeed
[i|mastodon-summary-#{timestamp now}|]
(TextString "Mastodon Digests")
(timestamp now)
whenJust (textFeed feed{feedEntries = entries}) $
\file -> writeFileLText out_file file

View file

@ -1,4 +1,4 @@
module Mail (main) where
module Main (main) where
import Control.Error (
throwE,

View file

@ -0,0 +1,49 @@
module Main (main) where
import Data.String.Interpolate (i)
import Data.Text qualified as Text
import Data.Text.Lazy qualified as LazyText
import Data.Time qualified as Time
import Relude
import System.FilePattern.Directory qualified as Directory
import Text.Atom.Feed qualified as Feed
import Text.Atom.Feed.Export qualified as Feed
import Witch
timestamp :: Time.UTCTime -> Text
timestamp = into . Time.formatTime Time.defaultTimeLocale "%Y-%m-%d %H:%M"
todayMask :: Time.UTCTime -> Directory.FilePattern
todayMask = Time.formatTime Time.defaultTimeLocale "%Y-%m-%d-*/index.html"
feedFromFileName :: Time.UTCTime -> Text -> Feed.Entry
feedFromFileName now file_name =
( Feed.nullEntry
folder_name
(Feed.TextString [i|mastodon digest #{digest_name}|])
(timestamp now)
)
{ Feed.entryLinks = [Feed.nullLink [i|http://hera.vpn.m-0.eu:8842/mastodon/#{file_name}|]]
}
where
digest_name = Text.drop 11 folder_name
folder_name =
Text.dropEnd 11 file_name
makeFeed :: Time.UTCTime -> [FilePath] -> Maybe LazyText.Text
makeFeed now file_names =
Feed.textFeed emptyFeed{Feed.feedEntries = feedFromFileName now . into <$> file_names}
where
emptyFeed =
Feed.nullFeed
[i|mastodon-summary-#{timestamp now}|]
(Feed.TextString "Mastodon Digests")
(timestamp now)
main :: IO ()
main = do
[out_file, dir] <- getArgs
now <- Time.getCurrentTime
file_names <- Directory.getDirectoryFiles dir [todayMask now]
whenJust (makeFeed now file_names) $
\file -> writeFileLText out_file file

View file

@ -1,4 +1,4 @@
module Main where
module Main (main) where
import Data.List.Extra qualified as L
import Data.List.NonEmpty (
@ -31,7 +31,6 @@ import Witch.Encoding (UTF_8)
-- TODO: use Text instead of linked lists of chars
type WeechatLog = [WeechatLine]
data WeechatLine = WeechatLine
{ wlDate :: Text
, wlTime :: Text