<commit_before>module Main where

import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Text as T
import           Data.Text.IO (writeFile)
import           Iptf.Hosts
import           Iptf.Ip
import           Iptf.Options
import           Network.HTTP.Conduit (simpleHttp)
import           Prelude hiding (writeFile)

ipFromWeb :: String -> IO (Either String IP)
ipFromWeb u = simpleHttp u >>= return . getIP . T.pack . L.unpack

run :: Options -> IO ()
run opts = do
  saved <- ipFromFile (path opts) (hostname opts)
  new   <- ipFromWeb  $ url opts
  do case new of
      Left  e -> print e
      Right i -> if saved == pure i
                 then return ()
                 else do
                   withFile (path opts) WriteMode $ \h ->
                     hPutStrLn h $ showIP i

main :: IO ()
main = getOptions >>= run<commit_msg>Update run to work with Hosts file<commit_after>module Main where

import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Text as T
import           Data.Text.IO (writeFile)
import           Iptf.Hosts
import           Iptf.Ip
import           Iptf.Options
import           Network.HTTP.Conduit (simpleHttp)
import           Prelude hiding (writeFile)

ipFromWeb :: String -> IO (Either String IP)
ipFromWeb u = simpleHttp u >>= return . getIP . T.pack . L.unpack

run :: Options -> IO ()
run opts = do
  let name = (hostname opts)
  tryWebIP <- ipFromWeb (url opts)
  case tryWebIP of
   Left e -> putStrLn e
   Right webIP -> do
     tryHosts <- readHosts (path opts)
     case tryHosts of
      Left e -> putStrLn e
      Right hosts -> do
        let tryFileIP = ipForHostname name hosts
        case tryFileIP of
         Nothing -> writeFile (path opts) $ toText (update hosts name webIP)
         Just fileIP  ->
           if webIP == fileIP
           then return ()
           else writeFile (path opts) $ toText (update hosts name webIP)

main :: IO ()
main = getOptions >>= run
{'fraction_non_alphanumeric': 0.08252674477840041, 'fraction_numerical': 0.0010188487009679063, 'mean_word_length': 2.0449612403100774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '593587', 'n_tokens_mistral': 587, 'n_tokens_neox': 580, 'n_words': 215}