seNameFromOodi :: Lang              -- ^ The 'Lang'uage to lookup.
                       -> Text              -- ^ The WebOodi page ID.
                       -> M (Maybe Text)    -- ^ The translation if found.
i18nCourseNameFromOodi lang pageId = do
    Config{..} <- ask

    ov         <- liftIO $ tryTakeMVar oodiVar
    oodiNames  <- case ov of
        Just x  -> return x
        Nothing -> readOodiNames
    liftIO $ putMVar oodiVar oodiNames

    case Map.lookup (lang, pageId) oodiNames of
        Just name -> return $ Just name
        Nothing   -> do
            raw <- liftIO $ fetch8859 (T.unpack $ weboodiLink weboodiUrl lang pageId)
            case getOodiName raw of
                Nothing   -> return Nothing
                Just name -> do
                    let newNames = Map.insert (lang, pageId) name oodiNames
                    liftIO $ do _ <- swapMVar oodiVar newNames
                                writeFile oodiNameFile (show newNames)
                    return $ Just name


{- | Reads the web page at the given URL and returns a utf-8 converted version
    of the page. WebOodi is encoded in iso-8859-1 encoding.
-}
fetch88
i18nCourseNameFromOodi :: Lang              -- ^ The 'Lang'uage to lookup.
                       -> Text              -- ^ The WebOodi page ID.
                       -> M (Maybe Text)
i18nCourseNameFromOodi lang pageId = do
    Config{..} <- ask

    ov         <- liftIO $ tryTakeMVar oodiVar
    oodiNames  <- case ov of
        Just x  -> return x
        Nothing -> readOodiNames
    liftIO $ putMVar oodiVar oodiNames

    case Map.lookup (lang, pageId) oodiNames of
        Just name -> return $ Just name
        Nothing   -> do
            raw <- liftIO $ fetch8859 (T.unpack $ weboodiLink weboodiUrl lang pageId)
            case getOodiName raw of
                Nothing   -> return Nothing
                Just name -> do
                    let newNames = Map.insert (lang, pageId) name oodiNames
                    liftIO $ do _ <- swapMVar oodiVar newNames
                                writeFile oodiNameFile (show newNames)
                    return $ Just name


{- | Reads the web page at the given URL and returns a utf-8 converted version
    of the page. WebOodi is encoded in iso-8859-1 encoding.
-}
i18nCourseNameFromOodi lang pageId = do
    Config{..} <- ask

    ov         <- liftIO $ tryTakeMVar oodiVar
    oodiNames  <- case ov of
        Just x  -> return x
        Nothing -> readOodiNames
    liftIO $ putMVar oodiVar oodiNames

    case Map.lookup (lang, pageId) oodiNames of
        Just name -> return $ Just name
        Nothing   -> do
            raw <- liftIO $ fetch8859 (T.unpack $ weboodiLink weboodiUrl lang pageId)
            case getOodiName raw of
                Nothing   -> return Nothing
                Just name -> do
                    let newNames = Map.insert (lang, pageId) name oodiNames
                    liftIO $ do _ <- swapMVar oodiVar newNames
                                writeFile oodiNameFile (show newNames)
                    return $ Just name


{- | Reads the web page at the given URL and returns a utf-8 converted version
    of the page. WebOodi is encoded in iso-8859-1 encoding.
-}