Add untf8 support
This commit is contained in:
parent
56291f80e6
commit
e56575d5c4
38
src/Main.hs
38
src/Main.hs
|
@ -10,15 +10,21 @@ import Network.HTTP.Conduit
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
import Data.Algorithm.Diff
|
import Data.Algorithm.Diff
|
||||||
import Data.Algorithm.DiffOutput
|
import Data.Algorithm.DiffOutput
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L8
|
import Data.ByteString.Lazy.UTF8 (toString)
|
||||||
|
|
||||||
|
|
||||||
data GeneratorState = IsRunning | IsFinished
|
data GeneratorState = IsRunning | IsFinished
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
getChanges :: Diff f -> Bool
|
isChanged :: Diff f -> Bool
|
||||||
getChanges (First _) = True
|
isChanged (First _) = True
|
||||||
getChanges _ = False
|
isChanged _ = False
|
||||||
|
|
||||||
|
getChanges :: [String] -> [String] -> Maybe String
|
||||||
|
getChanges now before = if (hasDiff ch) then Just res else Nothing
|
||||||
|
where ch = filter isChanged diff
|
||||||
|
diff = getDiff now before
|
||||||
|
res = foldr (\(First x) y -> x ++ " \n " ++ y) "" ch
|
||||||
|
|
||||||
-- Should stop the script if there's a checkbox with a keyword `stop`
|
-- Should stop the script if there's a checkbox with a keyword `stop`
|
||||||
showRunning :: [String] -> GeneratorState
|
showRunning :: [String] -> GeneratorState
|
||||||
|
@ -31,21 +37,29 @@ hasDiff :: [a] -> Bool
|
||||||
hasDiff [] = False
|
hasDiff [] = False
|
||||||
hasDiff _ = True
|
hasDiff _ = True
|
||||||
|
|
||||||
|
|
||||||
|
genOutput :: Maybe String -> String -> IO ()
|
||||||
|
genOutput (Just changes) time = do
|
||||||
|
putStrLn $ time ++ "\n " ++ changes
|
||||||
|
genOutput Nothing _ = return()
|
||||||
|
|
||||||
|
|
||||||
timecodeGenerator :: GeneratorState -> [String] -> UTCTime -> IO ()
|
timecodeGenerator :: GeneratorState -> [String] -> UTCTime -> IO ()
|
||||||
timecodeGenerator IsFinished _ _ = return ()
|
timecodeGenerator IsFinished _ _ = return ()
|
||||||
timecodeGenerator IsRunning text time = do
|
timecodeGenerator IsRunning prevFile time = do
|
||||||
html <- simpleHttp "https://hd.socks.town/s/h0jnEJQWy/download"
|
html <- simpleHttp "https://hd.socks.town/s/h0jnEJQWy/download"
|
||||||
currTime <- getCurrentTime
|
currTime <- getCurrentTime
|
||||||
let body = (splitOn ("\n")) . L8.unpack $ html
|
let newFile = (splitOn ("\n")) . toString $ html
|
||||||
print $ filter getChanges $ getDiff body text
|
let changes = getChanges newFile prevFile
|
||||||
print $ myFormatDiffTime (currTime, time)
|
let diffTime = myFormatDiffTime (currTime, time)
|
||||||
|
genOutput changes diffTime
|
||||||
-- Waiting for 1 second
|
-- Waiting for 1 second
|
||||||
threadDelay 1000000
|
threadDelay 10000
|
||||||
-- Creating a loop until `IsFinished`
|
-- Creating a loop until `IsFinished`
|
||||||
if showRunning body == IsRunning then
|
if showRunning newFile == IsRunning then
|
||||||
timecodeGenerator IsRunning body time
|
timecodeGenerator IsRunning newFile time
|
||||||
else
|
else
|
||||||
timecodeGenerator IsFinished body time
|
timecodeGenerator IsFinished newFile time
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|
|
@ -10,11 +10,12 @@ executable timecode-generator
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.14.3,
|
base >= 4.14.3,
|
||||||
bytestring,
|
bytestring,
|
||||||
|
utf8-string >= 1.0.2,
|
||||||
aeson,
|
aeson,
|
||||||
time,
|
time,
|
||||||
split,
|
split,
|
||||||
|
Diff,
|
||||||
HTTP >= 4000,
|
HTTP >= 4000,
|
||||||
http-client>= 0.6.4.1,
|
http-client>= 0.6.4.1,
|
||||||
http-conduit >= 2.3.8,
|
http-conduit >= 2.3.8,
|
||||||
tagsoup >= 0.14.6,
|
tagsoup >= 0.14.6
|
||||||
Diff
|
|
||||||
|
|
Loading…
Reference in a new issue