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 7e5bf9e8 authored by Hachemin Pierre-Yves's avatar Hachemin Pierre-Yves

Merge branch 'get2007' into 'master'

Get2007

See merge request !6
parents cfd7f52d 58016722
......@@ -8,28 +8,29 @@ 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()
url_final = url + 'page=1&year=' + str(year)
req = requests.get(url_final)
# url_final = url + 'page=1&year=' + str(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.write(str(dict_movies))
f.close()
for page in range(2, nb_of_pages+1):
time.sleep(5)
nb_of_pages = 550
# nb_of_pages = req.json()['total_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-dictionnary" + str(year) + ".txt", "w")
# f.write(str(dict_movies))
# f.close()
for page in range(163, nb_of_pages+1): #TODO: changer la page if needed
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 +38,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) + "-2.txt", "w")
f.write(str(dict_movies))
f.close()
return dict_movies
......@@ -54,4 +55,4 @@ def get_video_link(movie_id):
print(get_movie_ids(2005))
print(get_movie_ids(2010))
import ast
#L = ['Sithad108Og.','fBNpSRtfIUA', '2e-eXJ6HgkQ', 'tN1A2mVnrOM', 'myTaigPrbsg', 'b75lZw8nkvo']
def get_genre_from_link():
path = "./Link-dictionnaries/Link-dictionnary2000.txt"
file = open(path, "r").read()
dictyear = ast.literal_eval(file)
dict_inverse = {}
links_to_be_removed = []
for movie_id in dictyear.keys():
if dictyear[movie_id][1] != []:
dict_inverse[dictyear[movie_id][2]] = dictyear[movie_id][1][0]
else:
print(f'careful, link {dictyear[movie_id][2]} needs to be removed from the list')
links_to_be_removed += [dictyear[movie_id][2]]
return dict_inverse, links_to_be_removed
def get_output_list(L):
dict_inverse, links_to_be_removed = get_genre_from_link()
output = []
for link in L:
if link in links_to_be_removed:
L.remove(link)
else:
output += [dict_inverse[link]]
return output
print(get_output_list(L))
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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
f = open("spectrums_to_keep.txt", "w")
f.write(str(ok_files))
f.close()
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