human
Solve the following python programming problem given the following code:
@internet(log)
@with_session
def lookup_movie(title=None, year=None, rottentomatoes_id=None, smart_match=None, only_cached=False, session=None, api_key=None):
assistant
#Here is the Python program you requested.

    """Do a lookup from Rotten Tomatoes for the movie matching the passed arguments.
    Any combination of criteria can be passed, the most specific criteria specified will be used.
    :param rottentomatoes_id: rottentomatoes_id of desired movie
    :param string title: title of desired movie
    :param year: release year of desired movie
    :param smart_match: attempt to clean and parse title and year from a string
    :param only_cached: if this is specified, an online lookup will not occur if the movie is not in the cache
    :param session: optionally specify a session to use, if specified, returned Movie will be live in that session
    :param api_key: optionaly specify an API key to use
    :returns: The Movie object populated with data from Rotten Tomatoes
    :raises: PluginError if a match cannot be found or there are other problems with the lookup
    """
    if smart_match:
        title_parser = get_plugin_by_name(u'parsing').instance.parse_movie(smart_match)
        title = title_parser.name
        year = title_parser.year
        if ((title == u'') and (not (rottentomatoes_id or title))):
            raise PluginError((u'Failed    to    parse    name    from    %s' % smart_match))
    if title:
        search_string = title.lower()
        if year:
            search_string = (u'%s    %s' % (search_string, year))
    elif (not rottentomatoes_id):
        raise PluginError(u'No    criteria    specified    for    rotten    tomatoes    lookup')
    def id_str():
        return (u'<title=%s,year=%s,rottentomatoes_id=%s>' % (title, year, rottentomatoes_id))
    log.debug((u'Looking    up    rotten    tomatoes    information    for    %s' % id_str()))
    movie = None
    if rottentomatoes_id:
        movie = session.query(RottenTomatoesMovie).filter((RottenTomatoesMovie.id == rottentomatoes_id)).first()
    if ((not movie) and title):
        movie_filter = session.query(RottenTomatoesMovie).filter((func.lower(RottenTomatoesMovie.title) == title.lower()))
        if year:
            movie_filter = movie_filter.filter((RottenTomatoesMovie.year == year))
        movie = movie_filter.first()
        if (not movie):
            log.debug(u'No    matches    in    movie    cache    found,    checking    search    cache.')
            found = session.query(RottenTomatoesSearchResult).filter((func.lower(RottenTomatoesSearchResult.search) == search_string)).first()
            if (found and found.movie):
                log.debug(u'Movie    found    in    search    cache.')
                movie = found.movie
    if movie:
        if (movie.expired and (not only_cached)):
            log.debug((u'Cache    has    expired    for    %s,    attempting    to    refresh    from    Rotten    Tomatoes.' % id_str()))
            try:
                result = movies_info(movie.id, api_key)
                movie = _set_movie_details(movie, session, result, api_key)
             ...