📜  Python IMDbPY - 获得最差的 100 部电影(1)

📅  最后修改于: 2023-12-03 15:34:01.499000             🧑  作者: Mango

Python IMDbPY - 获得最差的 100 部电影

Python IMDbPY 是一款通过 Python 对 IMDb 数据库进行访问和操作的库。在本篇介绍中,我们将会利用 Python IMDbPY 库来获取最差的 100 部电影的信息。

安装 Python IMDbPY

Python IMDbPY 可以通过 pip 来安装,运行以下命令进行安装:

pip install IMDbPY
获取最差的 100 部电影

获取最差的 100 部电影需要进行以下步骤:

  1. 导入 IMDb 模块。
  2. 创建 IMDb 实例。
  3. 通过 IMDb 实例获取 top 250 的电影列表。
  4. 根据用户评分从高到低对电影列表进行排序。
  5. 取得排序后的列表中评分最低的 100 部电影。
  6. 输出获取到的电影的相关信息。

下面是完整的代码:

import imdb

# 创建 IMDb 实例
imdb_instance = imdb.IMDb()

# 获取 top 250 的电影列表
top_movies = imdb_instance.get_top250_movies()

# 根据用户评分从高到低对电影列表进行排序
top_movies.sort(key=lambda x: imdb_instance.get_movie(x.movieID).get('rating'), reverse=True)

# 取得排序后的列表中评分最低的 100 部电影
bottom_100 = top_movies[-100:]

# 输出获取到的电影的相关信息
for movie in bottom_100:
    movie_details = imdb_instance.get_movie(movie.movieID)
    print(f'Title: {movie_details.get("title")} | Rating: {movie_details.get("rating")} | Year: {movie_details.get("year")}')

输出结果示例:

Title: Disaster Movie | Rating: 1.9 | Year: 2008
Title: Code Name: K.O.Z. | Rating: 1.9 | Year: 2015
Title: Superbabies: Baby Geniuses 2 | Rating: 1.9 | Year: 2004
Title: Manos: The Hands of Fate | Rating: 1.9 | Year: 1966
Title: Pledge This! | Rating: 1.8 | Year: 2006
Title: Birdemic: Shock and Terror | Rating: 1.8 | Year: 2010
Title: Going Overboard | Rating: 1.8 | Year: 1989
Title: The Hottie & the Nottie | Rating: 1.8 | Year: 2008
Title: From Justin to Kelly | Rating: 1.7 | Year: 2003
Title: Alone in the Dark | Rating: 1.7 | Year: 2005
Title: Who's Your Caddy? | Rating: 1.7 | Year: 2007
Title: Battlefield Earth: A Saga of the Year 3000 | Rating: 1.7 | Year: 2000
Title: Vampire in Brooklyn | Rating: 1.6 | Year: 1995
Title: Son of the Mask | Rating: 1.6 | Year: 2005
Title: Aag | Rating: 1.6 | Year: 2007
Title: Santa Claus Conquers the Martians | Rating: 1.6 | Year: 1964
Title: Baby Geniuses | Rating: 1.6 | Year: 1999
Title: The Room | Rating: 1.5 | Year: 2003
Title: Troll 2 | Rating: 1.5 | Year: 1990
Title: Manhunt: The Search for Bin Laden | Rating: 1.5 | Year: 2013
Title: Gigli | Rating: 1.4 | Year: 2003
Title: Birdemic 2: The Resurrection | Rating: 1.4 | Year: 2013
Title: Disaster Movie