From 40eb73a48bf0cdf39a8e16aca80841f9edefef7b Mon Sep 17 00:00:00 2001 From: horhik Date: Thu, 10 Feb 2022 07:11:00 +0300 Subject: [PATCH] Print diffTime %H:%M:%S for each change --- src/Main.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Main.hs b/src/Main.hs index 9876711..e4ebee7 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -4,12 +4,15 @@ import Data.Char import Control.Concurrent import System.Environment import Data.Time.Clock +import Data.Time.Format +import Data.Time.Clock.POSIX import Network.HTTP.Conduit import Data.List.Split import Data.Algorithm.Diff import Data.Algorithm.DiffOutput import qualified Data.ByteString.Lazy.Char8 as L8 + data GeneratorState = IsRunning | IsFinished deriving (Eq) @@ -21,12 +24,21 @@ getChanges _ = False showRunning :: [String] -> GeneratorState showRunning html = IsRunning +myFormatDiffTime :: (UTCTime, UTCTime) -> String +myFormatDiffTime (a,b)= formatTime defaultTimeLocale "%H:%M:%S" . posixSecondsToUTCTime $ diffUTCTime a b + +hasDiff :: [a] -> Bool +hasDiff [] = False +hasDiff _ = True + timecodeGenerator :: GeneratorState -> [String] -> UTCTime -> IO () timecodeGenerator IsFinished _ _ = return () timecodeGenerator IsRunning text time = do html <- simpleHttp "https://hd.socks.town/s/h0jnEJQWy/download" + currTime <- getCurrentTime let body = (splitOn ("\n")) . L8.unpack $ html print $ filter getChanges $ getDiff body text + print $ myFormatDiffTime (currTime, time) -- Waiting for 1 second threadDelay 1000000 -- Creating a loop until `IsFinished`