import logging


def get_previous_version(versions: dict, app: str) -> str:
    """Looks in the app's .version_history to retrieve the prior version"""
    try:
        with open(f"{app}/.version_history", "r") as fh:
            lines = [line.strip() for line in fh]
    except FileNotFoundError:
        logging.warning(f"No .version_history for {app}")
        return ""

    if versions[app] != lines[-1]:
        logging.warning(
            f"Mismatch in data:\n\tCurrent version is {versions[app]}"
            f" but most recent line in .version_history is {lines[-1]}"
        )
        return ""
    elif len(lines) < 2:
        logging.warning("No prior version recorded")
        return ""
    return lines[-2]