From 6969f8db3f4be8c63a9f281faa4c27d1f4b54b8d Mon Sep 17 00:00:00 2001 From: horhik Date: Thu, 10 Feb 2022 10:09:44 +0300 Subject: [PATCH] add url property to fetchFile --- src/Main.hs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index e6688a5..c1d901c 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -47,16 +47,16 @@ genOutput (Just changes) time = do genOutput Nothing _ = return() -fetchFile :: IO [String] -fetchFile = do - html <- simpleHttp "https://hd.socks.town/s/h0jnEJQWy/download" +fetchFile :: String -> IO [String] +fetchFile url = do + html <- simpleHttp url return $ (splitOn ("\n")) . toString $ html -- Main Loop -timecodeGenerator :: GeneratorState -> [String] -> UTCTime -> IO () -timecodeGenerator IsFinished _ _ = return () -timecodeGenerator IsRunning prevFile time = do - newFile <- fetchFile +timecodeGenerator :: GeneratorState -> [String] -> UTCTime -> String -> IO () +timecodeGenerator IsFinished _ _ _ = return () +timecodeGenerator IsRunning prevFile time url = do + newFile <- fetchFile url currTime <- getCurrentTime let changes = getChanges newFile prevFile let diffTime = myFormatDiffTime (currTime, time) @@ -66,12 +66,13 @@ timecodeGenerator IsRunning prevFile time = do threadDelay 10000 -- Creating a loop until `IsFinished` if showRunning newFile == IsRunning then - timecodeGenerator IsRunning newFile time + timecodeGenerator IsRunning newFile time url else - timecodeGenerator IsFinished newFile time + timecodeGenerator IsFinished newFile time url main :: IO () main = do + let url = "https://hd.socks.town/s/h0jnEJQWy/download" time <- getCurrentTime - file <- fetchFile - timecodeGenerator IsRunning file time + file <- fetchFile url + timecodeGenerator IsRunning file time url