+
+
+
+
+
+get_login_cookie :: C.Cfg -> IO C.Cfg
+get_login_cookie cfg
+ | isNothing (C.username cfg) = return cfg
+ | isNothing (C.password cfg) = return cfg
+ | otherwise = do
+ let uname = fromJust $ C.username cfg
+ let pword = fromJust $ C.password cfg
+ li_result <- log_in uname pword
+
+ case li_result of
+ Left err -> do
+ let msg = "Failed to log in. Server response:\n" ++ (show err)
+ hPutStrLn stderr msg
+ return cfg
+ Right cj -> return $ cfg { C.cookie_jar = cj }
+
+
+-- | Try to parse the given article using HXT. We try a few different
+-- methods; if none of them work, we return 'Nothing'.
+get_article_contents :: C.Cfg -> URL -> IO (Maybe String)
+get_article_contents cfg article_name = do
+ my_article <- real_article_path article_name
+ is_file <- doesFileExist my_article
+ case is_file of
+ True -> do
+ contents <- Utf8.readFile my_article
+ return $ Just $ contents
+ False -> do
+ -- Download the URL.
+ html <- get_page (C.cookie_jar cfg) my_article
+
+ case html of
+ Left err -> do
+ let msg = "Failed to retrieve article. " ++
+ "Server response:\n" ++ (show err)
+ hPutStrLn stderr msg
+ return Nothing
+ Right lbs_article ->
+ return $ Just (toString lbs_article)