Created
December 28, 2021 08:13
-
-
Save yihong0618/0073ef00129db3459e4b5b2814f0408f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
API = "https://api.wmdb.tv/api/v1/top?type={movie_type}&skip=0&limit={limit}" | |
def get_top_movies(movie_type, limit=250): | |
r = requests.get(API.format(movie_type=movie_type, limit=limit)) | |
if not r.ok: | |
raise Exception(f"Can not get movies for {movie_type} type") | |
return r.json() | |
def main(): | |
douban_movies = get_top_movies("Douban") | |
douban_movies_imdb_ids = [d.get("imdbId") for d in douban_movies] | |
douban_movies_ids = [d.get("doubanId") for d in douban_movies] | |
imdb_movies = get_top_movies("Imdb") | |
imdb_movies_douban_ids = [i.get("doubanId") for i in imdb_movies] | |
imdb_movies_ids = [i.get("imdbId") for i in imdb_movies] | |
print(len(set(douban_movies_ids) - set(imdb_movies_douban_ids))) | |
print(len(set(imdb_movies_ids) - set(douban_movies_imdb_ids))) | |
i = 0 | |
j = 0 | |
same_rating_list = [] | |
close_rating_list = [] | |
max_diff_list = [] | |
max_diff = 0 | |
for d in douban_movies: | |
if d.get("imdbId") in imdb_movies_ids: | |
if d.get("imdbRating") == d.get("doubanRating"): | |
i += 1 | |
same_rating_list.append( | |
{ | |
"name": d.get("data")[0]["name"], | |
"doubanRating": d.get("doubanRating"), | |
"imdbRating": d.get("imdbRating"), | |
} | |
) | |
else: | |
diff = float(d.get("imdbRating")) - float(d.get("doubanRating")) | |
abs_diff = round(abs(diff), 2) | |
print(abs_diff) | |
max_diff = max(abs_diff, max_diff) | |
if abs_diff >= 1.0: | |
max_diff_list.append( | |
{ | |
"name": d.get("data")[0]["name"], | |
"doubanRating": d.get("doubanRating"), | |
"imdbRating": d.get("imdbRating"), | |
} | |
) | |
if abs_diff <= 0.2: | |
close_rating_list.append( | |
{ | |
"name": d.get("data")[0]["name"], | |
"doubanRating": d.get("doubanRating"), | |
"imdbRating": d.get("imdbRating"), | |
} | |
) | |
j += 1 | |
# print(len(same_rating_list), len(close_rating_list), len(max_diff_list)) | |
# print(f"Total {i} in same rating") | |
# print(f"Total {j} in diff 0.1 rating") | |
print("Have Same Rating:", same_rating_list) | |
print("Have close Rating:", close_rating_list) | |
print("Have different Rating:", max_diff_list) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment