Ejemplo n.º 1
0
def start(genre, year):
    if genre in all_genres:
        with open('movies.csv', 'rb') as csv_file:
            movie_reader = csv.reader(csv_file, delimiter='|', quotechar=' ')
            films = find_films(genre, year, movie_reader)
            random_film = get_random_film(films)

            film_title = random_film[1]
            film_rating = get_rating(random_film)
            film_imdb_url = random_film[4]

            result = {
                'film': film_title,
                'rating': film_rating,
                'url': film_imdb_url
            }
            return result
Ejemplo n.º 2
0
    patern = """<div class="titlePageSprite star-box-giga-star">"""
    start_position = 49 + raw_html_text.find(patern)
    result = raw_html_text[start_position:start_position+3]
    try:
        float(result)
    except:
        result = u"Ссылка для этого фильма не актуальна."

    return result


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--genre", help="genre")
    parser.add_argument("--year", help="year", type=int)
    args = parser.parse_args()

    genre = args.genre
    year = args.year

    if (genre is not None) & (year is not None):
        with open('movies.csv', 'rb') as csv_file:
            movie_reader = csv.reader(csv_file, delimiter='|', quotechar=' ')
            films = find_films(genre, year, movie_reader)
            random_film = get_random_film(films)
            print random_film[4]
            print get_rating(random_film)

    else:
        print(u'Слишком мало аргументов')