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 !

Commit 4531be5a authored by SoleneDc's avatar SoleneDc

changes in API manager not to write the year, file linkfile and file reader

parent f8d4571d
......@@ -8,7 +8,8 @@ url = 'https://api.themoviedb.org/3/discover/movie?api_key=e4c6a6f5fbd60b0316b7f
#il faut ajouter l'année après
url_get_video = "http://api.themoviedb.org/3/movie/" #157336/videos?api_key=e4c6a6f5fbd60b0316b7ff30e73bec74
API = 'api_key=e4c6a6f5fbd60b0316b7ff30e73bec74&language=en-US'
#API = 'api_key=e4c6a6f5fbd60b0316b7ff30e73bec74&language=en-US'
API = 'api_key=a9075982d1f7ce05cc45adec0e5f5358&language=en-US'
def get_movie_ids(year):
now1 = datetime.datetime.now()
......@@ -16,20 +17,19 @@ def get_movie_ids(year):
req = requests.get(url_final)
dict_movies = {}
nb_of_pages = req.json()['total_pages']
print(nb_of_pages)
for item in req.json()['results']:
movie_id = item['id']
video_link = get_video_link(movie_id)
dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
f = open("./Link-dictionnaries/Link-dictionnary2005.txt", "w")
f = open("./Link-dictionnaries/Link-dictionnary" + str(year) + ".txt", "w")
f.write(str(dict_movies))
f.close()
for page in range(2, nb_of_pages+1):
time.sleep(5)
time.sleep(7)
print(dict_movies)
print(len(dict_movies))
print(f"taking care of page # {page}...")
print(f"taking care of page # {page}... / ", nb_of_pages)
url_final = url + 'page=' + str(page) +'&year=' + str(year)
req = requests.get(url_final)
for item in req.json()['results']:
......@@ -37,7 +37,7 @@ def get_movie_ids(year):
video_link = get_video_link(movie_id)
if video_link != '':
dict_movies[movie_id] = [item['vote_average'], item["genre_ids"], video_link]
f = open("./Link-dictionnaries/Link-dictionnary2005.txt", "w")
f = open("./Link-dictionnaries/Link-dictionnary"+ str(year) + ".txt", "w")
f.write(str(dict_movies))
f.close()
return dict_movies
......@@ -54,4 +54,4 @@ def get_video_link(movie_id):
print(get_movie_ids(2005))
print(get_movie_ids(2008))
import cv2
import os
def valid_spectrums():
ok_files = []
for file in os.listdir("Spectrums_sample"):
img = cv2.imread('./Spectrums_sample/' + file, 1)
image = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
length, width, lab = image.shape
colors = []
for i in range(width):
tuple = (image[0][i][0], image[0][i][1], image[0][i][2])
if tuple not in colors:
colors += [tuple]
if len(colors) >= 10:
ok_files += [file]
break
return ok_files
print(valid_spectrums())
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):
path = "./Link-dictionnaries/Link-dictionnary" + str(year) +".txt"
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:
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())
print(translate_genre())
sum_genre = sum_genre([2001, 2003, 2004, 2005, 2006])
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment