import logging


def get_tweet_obj(tweet):
    """
    Retrieve the inner most tweet information.

    Quoted tweet gets preference over retweeted status.

    Args:
        tweet: The current level of tweet obj.

    Returns:
        tweet (json obj): The inner most tweet obj.
    """
    try:
        # Parse quoted status or fall through to next check
        if 'quoted_status' in tweet:
            return get_tweet_obj(tweet['quoted_status'])

        # Parse retweeted status or return as is.
        if 'retweeted_status' in tweet:
            return get_tweet_obj(tweet['retweeted_status'])
    except Exception as e:
        logging.error("Error while parsing tweet with id: {}\n{}".format(tweet['id'], e))
        return None

    return tweet