Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Reader.py 1.55 KB
Newer Older
1 2 3 4 5 6 7 8
import ast
import requests
import matplotlib.pyplot as plt

url = "https://api.themoviedb.org/3/genre/movie/list?"
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'

def get_genres(year):
9
    path = "./Link-dictionaries/Link-dictionary" + str(year) +".txt"
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    file = open(path, "r").read()
    dictyear = ast.literal_eval(file)
    dict_genres = {}
    for movie_id in dictyear.keys():
        genre_ids = dictyear[movie_id][1]
        for genre_id in genre_ids:
            if genre_id in dict_genres.keys():
                dict_genres[genre_id] += 1
            else:
                dict_genres[genre_id] = 1
    return dict_genres

def translate_genre():
    url_final = url + API
    req = requests.get(url_final)
    print(req.json()["genres"])

def sum_genre(list_years):
    final_dict_genre = {}
    for year in list_years:
30
        print(f'dealing with {year}...')
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
        dict_genre = get_genres(year)
        for key in dict_genre.keys():
            if key in final_dict_genre.keys():
                final_dict_genre[key] += dict_genre[key]
            else:
                final_dict_genre[key] = dict_genre[key]
    return final_dict_genre



# print(get_genres(2001).keys())
# #print(get_genres(2002).keys())
# print(get_genres(2003).keys())
# print(get_genres(2004).keys())
# print(get_genres(2005).keys())
46 47
#print(translate_genre())
sum_genre = sum_genre(range(2003, 2014))
48 49 50 51 52 53 54 55 56
L = []
for key in sum_genre.keys():
    L += [str(key)]
print(L, list(sum_genre.values()))
print(sum(list(sum_genre.values())))
plt.bar(L, list(sum_genre.values()))

plt.show()