From e93d4053b6a0334c22686ed10893bf6ad66deacd Mon Sep 17 00:00:00 2001 From: ValeZh Date: Tue, 18 Jul 2023 00:35:10 +0300 Subject: [PATCH 01/15] Lab2 --- lab2/main.py | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 lab2/main.py diff --git a/lab2/main.py b/lab2/main.py new file mode 100644 index 0000000..3b381b5 --- /dev/null +++ b/lab2/main.py @@ -0,0 +1,106 @@ +import requests + +class Films: + def __init__(self , data, genres): + print(data['results']) + self.data = data + self.films = data['results'] + self.genres = genres['genres'] + + def give_all_data(self): + print(data['results']) + + def give_data_with_index_3_19(self): + for i in range(3, 19, 4): + print(self.films[i]) + + def the_most_popular(self): + popularity_id = 0 + maximum_film = 0 + + print(len(self.films)) + for f in range(len(self.films)): + if maximum_film < int(self.films[f]['popularity']): + maximum_film = int(self.films[f]['popularity']) + popularity_id = f + print(popularity_id) + print(maximum_film) + + print(f"4.Name of the most popular title {self.films[popularity_id]['original_title']}") + + def finde_name_from_discription(self, word): + film_ind_lst = [] + index = 0 + for f in self.films: + if word in f['overview']: + film_ind_lst.append(index) + index += 1 + + print('5. Names of titles which has in description key words which a user put as parameters') + for answ in film_ind_lst: + print(self.films[answ]['original_title']) + + def collection_of_genres(self): + answer = set() + for f in self.films: + answer.add(tuple(f['genre_ids'])) + + print('6. Unique collection of present genres (the collection should not allow inserts)') + print(answer) + + def delete_film_with_genre(self, id_genre_del): + ind = 0 + result = [] + for f in self.films: + if id_genre_del in f['genre_ids']: + next() + else: + result.append(f) + + print('7. Delete all movies with user provided genre') + print(result) + +''' + def popular_genres(self): + dict_times_genres = {} + for g in self.genres: + dict_times_genres.update({g['id']}:0) + print(dict_times_genres) + +''' + + + + +headers = { +"accept": "application/json", +"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzMTI3NGFmYTRlNTUyMjRjYzRlN2Q0NmNlMTNkOTZjOSIsInN1YiI6IjVkNmZhMWZmNzdjMDFmMDAxMDU5NzQ4OSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.lbpgyXlOXwrbY0mUmP-zQpNAMCw_h-oaudAJB6Cn5c8" +} # токен для авторизации +respons = requests.get('https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&sort_by=popularity.desc&page=1', headers=headers) # возвращает json с данными +genres_resp = requests.get('https://api.themoviedb.org/3/genre/movie/list?language=en', headers=headers) +print(respons.json()) +print(genres_resp.json()) +genre_data = genres_resp.json() +data = respons.json() +print(data.keys()) +# import pdb;pdb.set_trace() +answer = Films(data, genre_data) + +# 2 answer +answer.give_all_data() +# 3 answers +answer.give_data_with_index_3_19() +# 4 answer +answer.the_most_popular() +# 5 answer +#word = input() +#answer.finde_name_from_discription(word) +# 6 answer +answer.collection_of_genres() +# 7 answer +#id_genre = input() +#answer.delete_film_with_genre(id_genre) +# 8 answer +# answer.popular_genres() +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ +#print(type(data)) \ No newline at end of file From bf75b93d66221c2d7fbff3c87f77ec3fa303b0e4 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Tue, 18 Jul 2023 19:37:40 +0300 Subject: [PATCH 02/15] added 9 - 10 tasks --- lab2/main.py | 42 ++++++++++++++++++++++++++++++++++++------ main.py | 10 ++++++++-- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 3b381b5..5b7933b 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -1,4 +1,6 @@ +import collections import requests +import csv class Films: def __init__(self , data, genres): @@ -47,6 +49,7 @@ def collection_of_genres(self): print('6. Unique collection of present genres (the collection should not allow inserts)') print(answer) + return answer def delete_film_with_genre(self, id_genre_del): ind = 0 @@ -59,15 +62,38 @@ def delete_film_with_genre(self, id_genre_del): print('7. Delete all movies with user provided genre') print(result) + return result -''' + from collections import Counter def popular_genres(self): - dict_times_genres = {} + lst_for_count = [] + for f in self.films: + for ids in f['genre_ids']: + lst_for_count.append(ids) + cnt = collections.Counter(lst_for_count) + for g in self.genres: - dict_times_genres.update({g['id']}:0) - print(dict_times_genres) + if g['id'] == cnt.most_common(3)[0][0] or g['id'] == cnt.most_common(3)[1][0] or g['id'] == cnt.most_common(3)[2][0]: + print(g['name']) + + print(cnt.most_common(3)) + + def group_films_by_genres(self): + group_dict = {} + group_dict = {g['id']: [] for g in self.genres} + for f in self.films: + for g in f['genre_ids']: + buff = group_dict[g] + buff.append(f['original_title']) + group_dict.update({g : buff}) + print(group_dict) + def copy_data_with_22(self): + copy_data = self.data + for f in copy_data['results']: + f['genre_ids'][0] = 22 + print(copy_data) + return(copy_data) -''' @@ -101,6 +127,10 @@ def popular_genres(self): #id_genre = input() #answer.delete_film_with_genre(id_genre) # 8 answer -# answer.popular_genres() +answer.popular_genres() +# 9 answer +answer.group_films_by_genres() +# 10 answer +answer.copy_data_with_22() # See PyCharm help at https://www.jetbrains.com/help/pycharm/ #print(type(data)) \ No newline at end of file diff --git a/main.py b/main.py index cefbe0b..b2002ab 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ - def print_hi(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. @@ -58,7 +57,12 @@ def first_positive_line(mass): return ind ind += 1 - +def shift_mass(matrix, k = 1): + for i, row in enumerate(matrix): + if i & 1 and (offset := k % len(row)) != 0: + for j in range(offset): + matrix[i].insert(0, matrix[i].pop(-1)) + print(matrix) mass = [[-1, -1, -1], [0, 7, 67], [0, 2, 0]] @@ -68,3 +72,5 @@ def first_positive_line(mass): # var 12 print(f'delete columns with 0 {delete_zero_from_mass(mass)}') print(f'first line with positive number {first_positive_line(mass)}') +# var +print(f'shift mass {shift_mass(mass)}') \ No newline at end of file From 284045dcb2cb3916a908758a370c6850bcbfa643 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Tue, 18 Jul 2023 22:38:08 +0300 Subject: [PATCH 03/15] all done!!! --- lab2/lab2.txt | 21 +++++++++++++++++++++ lab2/main.py | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 lab2/lab2.txt diff --git a/lab2/lab2.txt b/lab2/lab2.txt new file mode 100644 index 0000000..701f230 --- /dev/null +++ b/lab2/lab2.txt @@ -0,0 +1,21 @@ +Title,Popularity,Score,Last_day_in_cinema +Insidious: The Last Key,1032.8,6,2018-01-03 +The Flash,1081.0,6,2023-06-13 +Warhorse One,1085.8,5,2023-06-30 +Sheroes,1103.4,5,2023-06-23 +The Super Mario Bros. Movie,1105.9,7,2023-04-05 +Elemental,1126.0,7,2023-06-14 +The Darkest Minds,1130.4,7,2018-07-25 +Transformers: Rise of the Beasts,11857.0,7,2023-06-06 +John Wick: Chapter 4,1247.3,7,2023-03-22 +Barbie,1267.7,8,2023-07-19 +Spider-Man: Across the Spider-Verse,1268.4,8,2023-05-31 +The Out-Laws,1367.0,6,2023-07-07 +San Andreas,1513.3,6,2015-05-27 +Sound of Freedom,1759.5,8,2023-07-03 +Knights of the Zodiac,2030.3,6,2023-04-27 +Fast X,2250.5,7,2023-05-17 +Guardians of the Galaxy Vol. 3,4145.1,8,2023-05-03 +War of the Worlds: The Attack,859.8,6,2023-04-21 +Mission: Impossible - Dead Reckoning Part One,920.7,7,2023-07-08 +A Good Day to Die Hard,972.0,5,2013-02-06 diff --git a/lab2/main.py b/lab2/main.py index 5b7933b..4821026 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -1,6 +1,9 @@ import collections import requests import csv +from datetime import datetime, date, time, timedelta +from copy import deepcopy +#from collections import Counter class Films: def __init__(self , data, genres): @@ -64,7 +67,7 @@ def delete_film_with_genre(self, id_genre_del): print(result) return result - from collections import Counter + def popular_genres(self): lst_for_count = [] for f in self.films: @@ -94,8 +97,36 @@ def copy_data_with_22(self): print(copy_data) return(copy_data) - - + def make_collection(self, sort): + result_lst_dic = [] + buff_dict = {} + for f in self.films: + title = f['original_title'] + popular = format( f['popularity'], '.1f') + score = int(f['vote_average']) + str = f['release_date'] + #vvv = date(0, 2 ,2) + day = datetime.strptime(str,'%Y-%m-%d').date() + #f'{str}', '%m-%d-%Y').date() + buff_dict.update({'Title': title, 'Popularity': popular , 'Score': score, 'Last_day_in_cinema': day}) + unchanged_buff_dic = deepcopy(buff_dict) + result_lst_dic.append(unchanged_buff_dic) + print(result_lst_dic) + if sort == 1: + sorted_list = sorted(result_lst_dic, key=lambda x: x['Score']) + if sort == 2: + sorted_list = sorted(result_lst_dic, key=lambda x: x['Popularity']) + print(sorted_list) + return (sorted_list) + + def csv_file_maker(self, coll_dict): + with open('lab2.txt', mode='w') as csv_file: + fieldnames = ['Title','Popularity','Score','Last_day_in_cinema'] + writer = csv.DictWriter(csv_file, fieldnames=fieldnames) + + writer.writeheader() + for d in coll_dict: + writer.writerow(d) headers = { @@ -132,5 +163,9 @@ def copy_data_with_22(self): answer.group_films_by_genres() # 10 answer answer.copy_data_with_22() +# 11 answer +dict_coll = answer.make_collection(2) +# 12 answer +answer.csv_file_maker(dict_coll) # See PyCharm help at https://www.jetbrains.com/help/pycharm/ #print(type(data)) \ No newline at end of file From dd2cd62a8ba39746e5e0c13d5bde55a193182e58 Mon Sep 17 00:00:00 2001 From: ValeZh <128028729+ValeZh@users.noreply.github.com> Date: Tue, 18 Jul 2023 22:43:53 +0300 Subject: [PATCH 04/15] Delete main.py not needed there --- main.py | 76 --------------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index b2002ab..0000000 --- a/main.py +++ /dev/null @@ -1,76 +0,0 @@ - -def print_hi(name): - # Use a breakpoint in the code line below to debug your script. - print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. - -# var 18 -def find_zero_col_in_mass(mass): - count_col = 0 - buff = 0 - for i in mass: - for j in i: - if j == 0: - buff = 1 - if buff == 1: - count_col += 1 - buff = 0 - return count_col - - -def find_long_line_mass(mass): - result = 0 - k = 0 - find_less = None - for i in mass: - k += 1 - buff = set(i) - if find_less != None and len(buff) < len(find_less): - result = k - else: - find_less = buff - return result - -# var12 -def delete_zero_from_mass(mass): - ind = 0 - buff = 0 - ind_for_pop = set() - for m in mass: - for k in m: - if k == 0: - buff = 1 - if buff == 1: - ind_for_pop.add(tuple(m)) - buff = 0 - ind += 1 - - #import pdb;pdb.set_trace() - return [ m for m in mass if tuple(m) not in ind_for_pop ] - #return { "a":m for m in mass if tuple(m) not in ind_for_pop } - - -def first_positive_line(mass): - ind = 0 - for m in mass: - for k in m: - if k > 0: - return ind - ind += 1 - -def shift_mass(matrix, k = 1): - for i, row in enumerate(matrix): - if i & 1 and (offset := k % len(row)) != 0: - for j in range(offset): - matrix[i].insert(0, matrix[i].pop(-1)) - print(matrix) - -mass = [[-1, -1, -1], [0, 7, 67], [0, 2, 0]] - -# var 18 -print(f'zero columns {find_zero_col_in_mass(mass)}') -print(f'the longest string with the same elements {find_long_line_mass(mass)}') -# var 12 -print(f'delete columns with 0 {delete_zero_from_mass(mass)}') -print(f'first line with positive number {first_positive_line(mass)}') -# var -print(f'shift mass {shift_mass(mass)}') \ No newline at end of file From 88d48d8e310aa45be392c375dd57d23445a16f66 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Thu, 20 Jul 2023 14:22:58 +0300 Subject: [PATCH 05/15] not all done ispravit --- lab2/lab2.txt | 20 -------- lab2/main.py | 130 ++++++++++++++++++++++++++------------------------ 2 files changed, 68 insertions(+), 82 deletions(-) diff --git a/lab2/lab2.txt b/lab2/lab2.txt index 701f230..78d88ab 100644 --- a/lab2/lab2.txt +++ b/lab2/lab2.txt @@ -1,21 +1 @@ Title,Popularity,Score,Last_day_in_cinema -Insidious: The Last Key,1032.8,6,2018-01-03 -The Flash,1081.0,6,2023-06-13 -Warhorse One,1085.8,5,2023-06-30 -Sheroes,1103.4,5,2023-06-23 -The Super Mario Bros. Movie,1105.9,7,2023-04-05 -Elemental,1126.0,7,2023-06-14 -The Darkest Minds,1130.4,7,2018-07-25 -Transformers: Rise of the Beasts,11857.0,7,2023-06-06 -John Wick: Chapter 4,1247.3,7,2023-03-22 -Barbie,1267.7,8,2023-07-19 -Spider-Man: Across the Spider-Verse,1268.4,8,2023-05-31 -The Out-Laws,1367.0,6,2023-07-07 -San Andreas,1513.3,6,2015-05-27 -Sound of Freedom,1759.5,8,2023-07-03 -Knights of the Zodiac,2030.3,6,2023-04-27 -Fast X,2250.5,7,2023-05-17 -Guardians of the Galaxy Vol. 3,4145.1,8,2023-05-03 -War of the Worlds: The Attack,859.8,6,2023-04-21 -Mission: Impossible - Dead Reckoning Part One,920.7,7,2023-07-08 -A Good Day to Die Hard,972.0,5,2013-02-06 diff --git a/lab2/main.py b/lab2/main.py index 4821026..301fd24 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -1,25 +1,44 @@ import collections import requests import csv -from datetime import datetime, date, time, timedelta +from datetime import datetime from copy import deepcopy -#from collections import Counter + + +# from collections import Counter + class Films: - def __init__(self , data, genres): - print(data['results']) - self.data = data - self.films = data['results'] - self.genres = genres['genres'] + def __init__(self, page): + self.header = { + "accept": "application/json", + "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzMTI3NGFmYTRlNTUyMjRjYzRlN2Q0NmNlMTNkOTZjOSIsInN1YiI6IjVkNmZhMWZmNzdjMDFmMDAxMDU5NzQ4OSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.lbpgyXlOXwrbY0mUmP-zQpNAMCw_h-oaudAJB6Cn5c8" + } + self.page = page + self.films = [] + self.genres = [] + self.fetch_data() + self.fetch_genre() + + def fetch_data(self): + for i in range(1, int(self.page)): + respons = requests.get( + f'https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&sort_by=popularity.desc&page={i}', + headers=self.header) # возвращает json с данными + self.films.extend(respons.json()['results']) + + def fetch_genre(self): + genres_resp = requests.get('https://api.themoviedb.org/3/genre/movie/list?language=en', headers=self.header) + self.genres = genres_resp.json() def give_all_data(self): - print(data['results']) + return self.films - def give_data_with_index_3_19(self): - for i in range(3, 19, 4): - print(self.films[i]) + # def give_data_with_index_3_19(self): + # for i in range(3, 19, 4):#slicing + # print(self.films[i]) - def the_most_popular(self): + def the_most_popular(self):# использовать max lst popularity_id = 0 maximum_film = 0 @@ -33,7 +52,7 @@ def the_most_popular(self): print(f"4.Name of the most popular title {self.films[popularity_id]['original_title']}") - def finde_name_from_discription(self, word): + def finde_name_from_discription(self, word):# use comprehension film_ind_lst = [] index = 0 for f in self.films: @@ -45,7 +64,7 @@ def finde_name_from_discription(self, word): for answ in film_ind_lst: print(self.films[answ]['original_title']) - def collection_of_genres(self): + def collection_of_genres(self): # use comprehension answer = set() for f in self.films: answer.add(tuple(f['genre_ids'])) @@ -54,74 +73,71 @@ def collection_of_genres(self): print(answer) return answer - def delete_film_with_genre(self, id_genre_del): - ind = 0 + def delete_film_with_genre(self, id_genre_del):# comprehension илиilter result = [] for f in self.films: - if id_genre_del in f['genre_ids']: - next() - else: + if id_genre_del not in f['genre_ids']: result.append(f) print('7. Delete all movies with user provided genre') print(result) return result - def popular_genres(self): lst_for_count = [] - for f in self.films: + for f in self.films:#comprehension for ids in f['genre_ids']: lst_for_count.append(ids) cnt = collections.Counter(lst_for_count) - for g in self.genres: - if g['id'] == cnt.most_common(3)[0][0] or g['id'] == cnt.most_common(3)[1][0] or g['id'] == cnt.most_common(3)[2][0]: + for g in self.genres:# взять id + name + if g['id'] == cnt.most_common(3)[0][0] or g['id'] == cnt.most_common(3)[1][0] or g['id'] == \ + cnt.most_common(3)[2][0]: print(g['name']) print(cnt.most_common(3)) def group_films_by_genres(self): - group_dict = {} group_dict = {g['id']: [] for g in self.genres} - for f in self.films: + for f in self.films:# [фильм1, фильм2] - пары по жанру for g in f['genre_ids']: buff = group_dict[g] buff.append(f['original_title']) - group_dict.update({g : buff}) + group_dict.update({g: buff}) print(group_dict) - def copy_data_with_22(self): - copy_data = self.data - for f in copy_data['results']: + + def copy_data_with_22(self):# deepcopy + copy_data = self.films + + for f in copy_data: f['genre_ids'][0] = 22 print(copy_data) - return(copy_data) + print(self.films) + return (copy_data) def make_collection(self, sort): result_lst_dic = [] - buff_dict = {} + buff_dict = {} # named tuple for f in self.films: title = f['original_title'] - popular = format( f['popularity'], '.1f') + popular = format(f['popularity'], '.1f') score = int(f['vote_average']) str = f['release_date'] - #vvv = date(0, 2 ,2) - day = datetime.strptime(str,'%Y-%m-%d').date() - #f'{str}', '%m-%d-%Y').date() - buff_dict.update({'Title': title, 'Popularity': popular , 'Score': score, 'Last_day_in_cinema': day}) + # vvv = date(0, 2 ,2) + day = datetime.strptime(str, '%Y-%m-%d').date() + # f'{str}', '%m-%d-%Y').date() + buff_dict.update({'Title': title, 'Popularity': popular, 'Score': score, 'Last_day_in_cinema': day}) unchanged_buff_dic = deepcopy(buff_dict) result_lst_dic.append(unchanged_buff_dic) print(result_lst_dic) if sort == 1: - sorted_list = sorted(result_lst_dic, key=lambda x: x['Score']) - if sort == 2: - sorted_list = sorted(result_lst_dic, key=lambda x: x['Popularity']) + sorted_list = sorted(result_lst_dic, key=lambda x: x['Score'], x['Popularity'])# сортировка по 2 полям print(sorted_list) return (sorted_list) def csv_file_maker(self, coll_dict): with open('lab2.txt', mode='w') as csv_file: - fieldnames = ['Title','Popularity','Score','Last_day_in_cinema'] + fieldnames = ['Title', 'Popularity', 'Score', 'Last_day_in_cinema'] writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() @@ -129,38 +145,28 @@ def csv_file_maker(self, coll_dict): writer.writerow(d) -headers = { -"accept": "application/json", -"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzMTI3NGFmYTRlNTUyMjRjYzRlN2Q0NmNlMTNkOTZjOSIsInN1YiI6IjVkNmZhMWZmNzdjMDFmMDAxMDU5NzQ4OSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.lbpgyXlOXwrbY0mUmP-zQpNAMCw_h-oaudAJB6Cn5c8" -} # токен для авторизации -respons = requests.get('https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&sort_by=popularity.desc&page=1', headers=headers) # возвращает json с данными -genres_resp = requests.get('https://api.themoviedb.org/3/genre/movie/list?language=en', headers=headers) -print(respons.json()) -print(genres_resp.json()) -genre_data = genres_resp.json() -data = respons.json() -print(data.keys()) # import pdb;pdb.set_trace() -answer = Films(data, genre_data) +page = input() +answer = Films(page) # 2 answer answer.give_all_data() # 3 answers -answer.give_data_with_index_3_19() +#answer.give_data_with_index_3_19() # 4 answer -answer.the_most_popular() +#answer.the_most_popular() # 5 answer -#word = input() -#answer.finde_name_from_discription(word) +# word = input() +# answer.finde_name_from_discription(word) # 6 answer -answer.collection_of_genres() +#answer.collection_of_genres() # 7 answer -#id_genre = input() -#answer.delete_film_with_genre(id_genre) +# id_genre = input() +# answer.delete_film_with_genre(id_genre) # 8 answer -answer.popular_genres() +#answer.popular_genres() # 9 answer -answer.group_films_by_genres() +#answer.group_films_by_genres() # 10 answer answer.copy_data_with_22() # 11 answer @@ -168,4 +174,4 @@ def csv_file_maker(self, coll_dict): # 12 answer answer.csv_file_maker(dict_coll) # See PyCharm help at https://www.jetbrains.com/help/pycharm/ -#print(type(data)) \ No newline at end of file +# print(type(data)) From 1aa40985e7f0257c67e59fb96e67c16f3f370094 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Sun, 23 Jul 2023 16:02:21 +0300 Subject: [PATCH 06/15] I changed everything except 8 and 11 --- lab2/main.py | 116 ++++++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 76 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 301fd24..0d6b75b 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -21,7 +21,7 @@ def __init__(self, page): self.fetch_genre() def fetch_data(self): - for i in range(1, int(self.page)): + for i in range(1, int(self.page) + 1): respons = requests.get( f'https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&sort_by=popularity.desc&page={i}', headers=self.header) # возвращает json с данными @@ -34,86 +34,50 @@ def fetch_genre(self): def give_all_data(self): return self.films - # def give_data_with_index_3_19(self): - # for i in range(3, 19, 4):#slicing - # print(self.films[i]) + def give_data_with_index_3_19(self): + x = slice(3,19,4) + return self.films[x] def the_most_popular(self):# использовать max lst - popularity_id = 0 - maximum_film = 0 - - print(len(self.films)) - for f in range(len(self.films)): - if maximum_film < int(self.films[f]['popularity']): - maximum_film = int(self.films[f]['popularity']) - popularity_id = f - print(popularity_id) - print(maximum_film) - - print(f"4.Name of the most popular title {self.films[popularity_id]['original_title']}") - - def finde_name_from_discription(self, word):# use comprehension - film_ind_lst = [] - index = 0 - for f in self.films: - if word in f['overview']: - film_ind_lst.append(index) - index += 1 + most_popular_film = max(self.films, key=lambda x:x['popularity'])['original_title'] + return most_popular_film - print('5. Names of titles which has in description key words which a user put as parameters') - for answ in film_ind_lst: - print(self.films[answ]['original_title']) + def finde_name_from_discription(self, word = 'planet'):# use comprehension + lst_with_word = [f['original_title'] for f in self.films if word in f['overview'] ] # f['original_title'] значение котовые возвращается ( for f in self.films) обычный цикл (if word in f['overview']) если выполняется условие lst_with_word.append(f)???? + return lst_with_word - def collection_of_genres(self): # use comprehension - answer = set() - for f in self.films: - answer.add(tuple(f['genre_ids'])) - print('6. Unique collection of present genres (the collection should not allow inserts)') - print(answer) + def collection_of_genres(self): # use comprehension + answer = {tuple(f['genre_ids']) for f in self.films } return answer - def delete_film_with_genre(self, id_genre_del):# comprehension илиilter - result = [] - for f in self.films: - if id_genre_del not in f['genre_ids']: - result.append(f) - - print('7. Delete all movies with user provided genre') - print(result) + def delete_film_with_genre(self, id_genre_del):# comprehension или iter, не очень поняла зачем iter + result = [f for f in self.films if int(id_genre_del) not in f['genre_ids']] return result def popular_genres(self): - lst_for_count = [] - for f in self.films:#comprehension - for ids in f['genre_ids']: - lst_for_count.append(ids) + lst_for_count = [f for f in self.films for ids in f['genre_ids']] cnt = collections.Counter(lst_for_count) - - for g in self.genres:# взять id + name + lst_result = [g for g in range(3)] + for g in self.genres:# взять id + name я не знаю как по другому if g['id'] == cnt.most_common(3)[0][0] or g['id'] == cnt.most_common(3)[1][0] or g['id'] == \ cnt.most_common(3)[2][0]: print(g['name']) print(cnt.most_common(3)) + return cnt.most_common(3) + def group_films_by_genres(self): - group_dict = {g['id']: [] for g in self.genres} - for f in self.films:# [фильм1, фильм2] - пары по жанру - for g in f['genre_ids']: - buff = group_dict[g] - buff.append(f['original_title']) - group_dict.update({g: buff}) - print(group_dict) + group_films1 = {(f['original_title'],k['original_title']) for f in self.films for k in self.films if list(set(f['genre_ids']) & set(k['genre_ids'])) != []} + return group_films1 - def copy_data_with_22(self):# deepcopy - copy_data = self.films + def copy_data_with_22(self):# deepcopy + copy_data = deepcopy(self.films) for f in copy_data: f['genre_ids'][0] = 22 - print(copy_data) - print(self.films) - return (copy_data) + return copy_data def make_collection(self, sort): result_lst_dic = [] @@ -130,10 +94,10 @@ def make_collection(self, sort): unchanged_buff_dic = deepcopy(buff_dict) result_lst_dic.append(unchanged_buff_dic) print(result_lst_dic) - if sort == 1: - sorted_list = sorted(result_lst_dic, key=lambda x: x['Score'], x['Popularity'])# сортировка по 2 полям - print(sorted_list) - return (sorted_list) +# if sort == 1: +# sorted_list = sorted(result_lst_dic, key=lambda x: x['Score'], x['Popularity'])# сортировка по 2 полям +# print(sorted_list) +# return (sorted_list) def csv_file_maker(self, coll_dict): with open('lab2.txt', mode='w') as csv_file: @@ -141,8 +105,8 @@ def csv_file_maker(self, coll_dict): writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() - for d in coll_dict: - writer.writerow(d) +# for d in coll_dict: +# writer.writerow(d) # import pdb;pdb.set_trace() @@ -150,25 +114,25 @@ def csv_file_maker(self, coll_dict): answer = Films(page) # 2 answer -answer.give_all_data() +print(f'2. Give a user all data {answer.give_all_data()}') # 3 answers -#answer.give_data_with_index_3_19() +print(f'3. All data about movies with indexes from 3 till 19 with step 4 {answer.give_data_with_index_3_19()}') # 4 answer -#answer.the_most_popular() +print(f'4. Name of the most popular title {answer.the_most_popular()}') # 5 answer -# word = input() -# answer.finde_name_from_discription(word) +word = input() +print(f'5. Names of titles which has in description key words which a user put as parameters {answer.finde_name_from_discription(word)}') # 6 answer -#answer.collection_of_genres() +print(answer.collection_of_genres()) # 7 answer -# id_genre = input() -# answer.delete_film_with_genre(id_genre) +id_genre = input() +print(f'7. Delete all movies with user provided genre{answer.delete_film_with_genre(id_genre)}') # 8 answer -#answer.popular_genres() +#print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') # 9 answer -#answer.group_films_by_genres() +print(f'9. Collection of film titles grouped in pairs by common genres{answer.group_films_by_genres()}') # 10 answer -answer.copy_data_with_22() +print(f'10. Return initial data and copy of initial data where first id in list of film genres was replaced with 22 {answer.copy_data_with_22()}') # 11 answer dict_coll = answer.make_collection(2) # 12 answer From 58e16e02cf87ed6bdc4a85b5ad30842e4cbdb1d0 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Fri, 28 Jul 2023 17:25:35 +0300 Subject: [PATCH 07/15] I forget to commit everything done --- lab2/main.py | 146 ++++++++++++++++++++++++--------------------------- 1 file changed, 70 insertions(+), 76 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 0d6b75b..f21ea86 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -1,7 +1,7 @@ import collections import requests import csv -from datetime import datetime +from datetime import datetime, timedelta from copy import deepcopy @@ -9,19 +9,19 @@ class Films: - def __init__(self, page): + def __init__(self, numb_page): self.header = { "accept": "application/json", "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzMTI3NGFmYTRlNTUyMjRjYzRlN2Q0NmNlMTNkOTZjOSIsInN1YiI6IjVkNmZhMWZmNzdjMDFmMDAxMDU5NzQ4OSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.lbpgyXlOXwrbY0mUmP-zQpNAMCw_h-oaudAJB6Cn5c8" } - self.page = page + self.page = numb_page self.films = [] self.genres = [] self.fetch_data() self.fetch_genre() def fetch_data(self): - for i in range(1, int(self.page) + 1): + for i in range(1, self.page + 1): respons = requests.get( f'https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&sort_by=popularity.desc&page={i}', headers=self.header) # возвращает json с данными @@ -35,106 +35,100 @@ def give_all_data(self): return self.films def give_data_with_index_3_19(self): - x = slice(3,19,4) - return self.films[x] + return self.films[3:19:4] - def the_most_popular(self):# использовать max lst - most_popular_film = max(self.films, key=lambda x:x['popularity'])['original_title'] - return most_popular_film + def the_most_popular(self): # использовать max lst + return max(self.films, key=lambda x: x['popularity'])['original_title'] - def finde_name_from_discription(self, word = 'planet'):# use comprehension - lst_with_word = [f['original_title'] for f in self.films if word in f['overview'] ] # f['original_title'] значение котовые возвращается ( for f in self.films) обычный цикл (if word in f['overview']) если выполняется условие lst_with_word.append(f)???? - return lst_with_word + def finde_name_from_discription(self, word='planet'): # use comprehension + # f['original_title'] значение котовые возвращается ( for f in self.films) + # обычный цикл (if word in f['overview']) если выполняется условие lst_with_word.append(f)???? + return [f['original_title'] for f in self.films if word in f[ + 'overview']] + def collection_of_genres(self): # use comprehension return в одну строку без создания переменной + answer_collect = frozenset(n for f in self.films for n in f['genre_ids']) + return answer_collect - def collection_of_genres(self): # use comprehension - answer = {tuple(f['genre_ids']) for f in self.films } - return answer - - def delete_film_with_genre(self, id_genre_del):# comprehension или iter, не очень поняла зачем iter + def delete_film_with_genre(self, id_genre_del): # comprehension или filter result = [f for f in self.films if int(id_genre_del) not in f['genre_ids']] return result def popular_genres(self): - lst_for_count = [f for f in self.films for ids in f['genre_ids']] - cnt = collections.Counter(lst_for_count) - lst_result = [g for g in range(3)] - for g in self.genres:# взять id + name я не знаю как по другому - if g['id'] == cnt.most_common(3)[0][0] or g['id'] == cnt.most_common(3)[1][0] or g['id'] == \ - cnt.most_common(3)[2][0]: - print(g['name']) - - print(cnt.most_common(3)) - return cnt.most_common(3) - + lst_for_count = [ids for f in self.films for ids in f['genre_ids']] + cnt = collections.Counter(lst_for_count).most_common(3) + x = {i['id']: i['name'] for i in self.genres} + most_genre = [(x[i[0]], i[1]) for i in cnt] + return most_genre def group_films_by_genres(self): - group_films1 = {(f['original_title'],k['original_title']) for f in self.films for k in self.films if list(set(f['genre_ids']) & set(k['genre_ids'])) != []} + group_films1 = {(f['original_title'], k['original_title']) for idx, f in enumerate(self.films) for k in self.films[idx:] if + set(f['genre_ids']) & set(k['genre_ids'])} return group_films1 - - def copy_data_with_22(self):# deepcopy - copy_data = deepcopy(self.films) - for f in copy_data: - f['genre_ids'][0] = 22 - return copy_data - - def make_collection(self, sort): - result_lst_dic = [] - buff_dict = {} # named tuple - for f in self.films: - title = f['original_title'] - popular = format(f['popularity'], '.1f') - score = int(f['vote_average']) - str = f['release_date'] - # vvv = date(0, 2 ,2) - day = datetime.strptime(str, '%Y-%m-%d').date() - # f'{str}', '%m-%d-%Y').date() - buff_dict.update({'Title': title, 'Popularity': popular, 'Score': score, 'Last_day_in_cinema': day}) - unchanged_buff_dic = deepcopy(buff_dict) - result_lst_dic.append(unchanged_buff_dic) + @staticmethod + def change_22_for_map(x): # поменять названия + x['genre_ids'][0] = 22 + return x + + def copy_data_with_22(self): # deepcopy + map + return list(map(self.change_22_for_map, deepcopy(self.films))) + + @staticmethod + def make_dict(f): + title = f['original_title'] + popular = format(f['popularity'], '.1f') + score = int(f['vote_average']) + realase = f['release_date'] + day = datetime.strptime(realase, '%Y-%m-%d') + timedelta(weeks=8) + return {'Title': title, 'Popularity': popular, 'Score': score, 'Last_day_in_cinema': day} + + def make_collection(self): + result_lst_dic = [self.make_dict(f) for f in self.films] # named tuple print(result_lst_dic) -# if sort == 1: -# sorted_list = sorted(result_lst_dic, key=lambda x: x['Score'], x['Popularity'])# сортировка по 2 полям -# print(sorted_list) -# return (sorted_list) + sorted_list = sorted(result_lst_dic, key=lambda x: (x['Score'], x['Popularity'])) # сортировка по 2 полям + print(sorted_list) + return sorted_list - def csv_file_maker(self, coll_dict): + @staticmethod + def csv_file_maker(coll_dict): with open('lab2.txt', mode='w') as csv_file: fieldnames = ['Title', 'Popularity', 'Score', 'Last_day_in_cinema'] writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() -# for d in coll_dict: -# writer.writerow(d) + writer.writerows(coll_dict) # import pdb;pdb.set_trace() -page = input() +print('Write number of page') +page = int(input()) answer = Films(page) -# 2 answer -print(f'2. Give a user all data {answer.give_all_data()}') -# 3 answers -print(f'3. All data about movies with indexes from 3 till 19 with step 4 {answer.give_data_with_index_3_19()}') -# 4 answer -print(f'4. Name of the most popular title {answer.the_most_popular()}') -# 5 answer -word = input() -print(f'5. Names of titles which has in description key words which a user put as parameters {answer.finde_name_from_discription(word)}') -# 6 answer -print(answer.collection_of_genres()) -# 7 answer -id_genre = input() -print(f'7. Delete all movies with user provided genre{answer.delete_film_with_genre(id_genre)}') -# 8 answer -#print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') +# # 2 answer +# print(f'2. Give a user all data {answer.give_all_data()}') +# # 3 answers +# print(f'3. All data about movies with indexes from 3 till 19 with step 4 {answer.give_data_with_index_3_19()}') +# # 4 answer +# print(f'4. Name of the most popular title {answer.the_most_popular()}') +# # 5 answer +# word = input() +# print( +# f'5. Names of titles which has in description key words which a user put as parameters {answer.finde_name_from_discription(word)}') +# # 6 answer +# print(answer.collection_of_genres()) +# # 7 answer +# id_genre = input() +# print(f'7. Delete all movies with user provided genre{answer.delete_film_with_genre(id_genre)}') +# # 8 answer +# # print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') # 9 answer print(f'9. Collection of film titles grouped in pairs by common genres{answer.group_films_by_genres()}') # 10 answer -print(f'10. Return initial data and copy of initial data where first id in list of film genres was replaced with 22 {answer.copy_data_with_22()}') +print( + f'10. Return initial data and copy of initial data where first id in list of film genres was replaced with 22 {answer.copy_data_with_22()}') # 11 answer -dict_coll = answer.make_collection(2) +dict_coll = answer.make_collection() # 12 answer answer.csv_file_maker(dict_coll) # See PyCharm help at https://www.jetbrains.com/help/pycharm/ From e344df369c3aa94756ad56d6b1e147de9b555c81 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Fri, 28 Jul 2023 17:29:03 +0300 Subject: [PATCH 08/15] I forget to commit everything done --- lab2/lab2.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lab2/lab2.txt b/lab2/lab2.txt index 78d88ab..9ec923f 100644 --- a/lab2/lab2.txt +++ b/lab2/lab2.txt @@ -1 +1,21 @@ Title,Popularity,Score,Last_day_in_cinema +Pan Samochodzik i templariusze,1050.4,6,2023-09-06 00:00:00 +Knights of the Zodiac,1336.6,6,2023-06-22 00:00:00 +Warhorse One,1879.4,6,2023-08-25 00:00:00 +The Little Mermaid,2078.2,6,2023-07-13 00:00:00 +The Flash,5930.1,6,2023-08-08 00:00:00 +The Out-Laws,840.4,6,2023-09-01 00:00:00 +Bird Box Barcelona,985.9,6,2023-09-08 00:00:00 +Elemental,1106.1,7,2023-08-09 00:00:00 +John Wick: Chapter 4,1130.0,7,2023-05-17 00:00:00 +The Super Mario Bros. Movie,1134.7,7,2023-05-31 00:00:00 +Fast X,2017.6,7,2023-07-12 00:00:00 +: ˳ ,2211.9,7,2023-04-27 00:00:00 +"Ruby Gillman, Teenage Kraken",2776.7,7,2023-08-23 00:00:00 +Transformers: Rise of the Beasts,5458.2,7,2023-08-01 00:00:00 +Barbie,6058.2,7,2023-09-13 00:00:00 +The Darkest Minds,792.4,7,2018-09-19 00:00:00 +Spider-Man: Across the Spider-Verse,1134.0,8,2023-07-26 00:00:00 +Sound of Freedom,1310.6,8,2023-08-28 00:00:00 +Oppenheimer,1449.3,8,2023-09-13 00:00:00 +Guardians of the Galaxy Vol. 3,2446.6,8,2023-06-28 00:00:00 From 37b877cca5e6f6aa0bd75fae7c34912fdadaa2af Mon Sep 17 00:00:00 2001 From: ValeZh Date: Fri, 4 Aug 2023 17:20:32 +0300 Subject: [PATCH 09/15] ok --- lab2/main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index f21ea86..63368d0 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -11,8 +11,8 @@ class Films: def __init__(self, numb_page): self.header = { - "accept": "application/json", - "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzMTI3NGFmYTRlNTUyMjRjYzRlN2Q0NmNlMTNkOTZjOSIsInN1YiI6IjVkNmZhMWZmNzdjMDFmMDAxMDU5NzQ4OSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.lbpgyXlOXwrbY0mUmP-zQpNAMCw_h-oaudAJB6Cn5c8" + 'accept': 'application/json', + 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzMTI3NGFmYTRlNTUyMjRjYzRlN2Q0NmNlMTNkOTZjOSIsInN1YiI6IjVkNmZhMWZmNzdjMDFmMDAxMDU5NzQ4OSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.lbpgyXlOXwrbY0mUmP-zQpNAMCw_h-oaudAJB6Cn5c8' } self.page = numb_page self.films = [] @@ -47,12 +47,10 @@ def finde_name_from_discription(self, word='planet'): # use comprehension 'overview']] def collection_of_genres(self): # use comprehension return в одну строку без создания переменной - answer_collect = frozenset(n for f in self.films for n in f['genre_ids']) - return answer_collect + return frozenset(n for f in self.films for n in f['genre_ids']) def delete_film_with_genre(self, id_genre_del): # comprehension или filter - result = [f for f in self.films if int(id_genre_del) not in f['genre_ids']] - return result + return [f for f in self.films if int(id_genre_del) not in f['genre_ids']] def popular_genres(self): lst_for_count = [ids for f in self.films for ids in f['genre_ids']] From 8ad4ec99a11a34649b557370049c83e0ce65e44d Mon Sep 17 00:00:00 2001 From: ValeZh Date: Mon, 21 Aug 2023 13:14:40 +0300 Subject: [PATCH 10/15] test commit --- lab2/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 63368d0..74e86ec 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -43,8 +43,7 @@ def the_most_popular(self): # использовать max lst def finde_name_from_discription(self, word='planet'): # use comprehension # f['original_title'] значение котовые возвращается ( for f in self.films) # обычный цикл (if word in f['overview']) если выполняется условие lst_with_word.append(f)???? - return [f['original_title'] for f in self.films if word in f[ - 'overview']] + return [f['original_title'] for f in self.films if word in f['overview']] def collection_of_genres(self): # use comprehension return в одну строку без создания переменной return frozenset(n for f in self.films for n in f['genre_ids']) @@ -60,9 +59,8 @@ def popular_genres(self): return most_genre def group_films_by_genres(self): - group_films1 = {(f['original_title'], k['original_title']) for idx, f in enumerate(self.films) for k in self.films[idx:] if + return {(f['original_title'], k['original_title']) for idx, f in enumerate(self.films) for k in self.films[idx:] if set(f['genre_ids']) & set(k['genre_ids'])} - return group_films1 @staticmethod def change_22_for_map(x): # поменять названия From b6241ed35b3c0f43f1c2b8f0f4f98d98caf4bb62 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Mon, 21 Aug 2023 13:22:56 +0300 Subject: [PATCH 11/15] I clear comments --- lab2/main.py | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 74e86ec..068466e 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -41,11 +41,9 @@ def the_most_popular(self): # использовать max lst return max(self.films, key=lambda x: x['popularity'])['original_title'] def finde_name_from_discription(self, word='planet'): # use comprehension - # f['original_title'] значение котовые возвращается ( for f in self.films) - # обычный цикл (if word in f['overview']) если выполняется условие lst_with_word.append(f)???? return [f['original_title'] for f in self.films if word in f['overview']] - def collection_of_genres(self): # use comprehension return в одну строку без создания переменной + def collection_of_genres(self): return frozenset(n for f in self.films for n in f['genre_ids']) def delete_film_with_genre(self, id_genre_del): # comprehension или filter @@ -63,11 +61,11 @@ def group_films_by_genres(self): set(f['genre_ids']) & set(k['genre_ids'])} @staticmethod - def change_22_for_map(x): # поменять названия + def change_22_for_map(x): x['genre_ids'][0] = 22 return x - def copy_data_with_22(self): # deepcopy + map + def copy_data_with_22(self): return list(map(self.change_22_for_map, deepcopy(self.films))) @staticmethod @@ -80,9 +78,9 @@ def make_dict(f): return {'Title': title, 'Popularity': popular, 'Score': score, 'Last_day_in_cinema': day} def make_collection(self): - result_lst_dic = [self.make_dict(f) for f in self.films] # named tuple + result_lst_dic = [self.make_dict(f) for f in self.films] print(result_lst_dic) - sorted_list = sorted(result_lst_dic, key=lambda x: (x['Score'], x['Popularity'])) # сортировка по 2 полям + sorted_list = sorted(result_lst_dic, key=lambda x: (x['Score'], x['Popularity'])) print(sorted_list) return sorted_list @@ -96,28 +94,27 @@ def csv_file_maker(coll_dict): writer.writerows(coll_dict) -# import pdb;pdb.set_trace() + print('Write number of page') page = int(input()) answer = Films(page) -# # 2 answer -# print(f'2. Give a user all data {answer.give_all_data()}') -# # 3 answers -# print(f'3. All data about movies with indexes from 3 till 19 with step 4 {answer.give_data_with_index_3_19()}') -# # 4 answer -# print(f'4. Name of the most popular title {answer.the_most_popular()}') -# # 5 answer -# word = input() -# print( -# f'5. Names of titles which has in description key words which a user put as parameters {answer.finde_name_from_discription(word)}') -# # 6 answer -# print(answer.collection_of_genres()) -# # 7 answer -# id_genre = input() -# print(f'7. Delete all movies with user provided genre{answer.delete_film_with_genre(id_genre)}') -# # 8 answer -# # print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') +# 2 answer +print(f'2. Give a user all data {answer.give_all_data()}') +# 3 answers +print(f'3. All data about movies with indexes from 3 till 19 with step 4 {answer.give_data_with_index_3_19()}') +# 4 answer +print(f'4. Name of the most popular title {answer.the_most_popular()}') +# 5 answer +word = input() +print(f'5. Names of titles which has in description key words which a user put as parameters {answer.finde_name_from_discription(word)}') +# 6 answer +print(answer.collection_of_genres()) +# 7 answer +id_genre = input() +print(f'7. Delete all movies with user provided genre{answer.delete_film_with_genre(id_genre)}') +# 8 answer +# print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') # 9 answer print(f'9. Collection of film titles grouped in pairs by common genres{answer.group_films_by_genres()}') # 10 answer From 2cd088276643bfcd6b8e4d2514d1b1d90cbbceb7 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Mon, 21 Aug 2023 13:25:16 +0300 Subject: [PATCH 12/15] I clear comments --- lab2/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 068466e..0891051 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -24,7 +24,7 @@ def fetch_data(self): for i in range(1, self.page + 1): respons = requests.get( f'https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&sort_by=popularity.desc&page={i}', - headers=self.header) # возвращает json с данными + headers=self.header) self.films.extend(respons.json()['results']) def fetch_genre(self): @@ -37,16 +37,16 @@ def give_all_data(self): def give_data_with_index_3_19(self): return self.films[3:19:4] - def the_most_popular(self): # использовать max lst + def the_most_popular(self): return max(self.films, key=lambda x: x['popularity'])['original_title'] - def finde_name_from_discription(self, word='planet'): # use comprehension + def finde_name_from_discription(self, word='planet'): return [f['original_title'] for f in self.films if word in f['overview']] def collection_of_genres(self): return frozenset(n for f in self.films for n in f['genre_ids']) - def delete_film_with_genre(self, id_genre_del): # comprehension или filter + def delete_film_with_genre(self, id_genre_del): return [f for f in self.films if int(id_genre_del) not in f['genre_ids']] def popular_genres(self): From 9e97a6a29df0c54db0471a390566c7f0aec4d798 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Mon, 21 Aug 2023 13:26:07 +0300 Subject: [PATCH 13/15] all done --- lab2/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab2/main.py b/lab2/main.py index 0891051..0d663d9 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -114,7 +114,7 @@ def csv_file_maker(coll_dict): id_genre = input() print(f'7. Delete all movies with user provided genre{answer.delete_film_with_genre(id_genre)}') # 8 answer -# print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') +print(f'8. Names of most popular genres with numbers of time they appear in the data {answer.popular_genres()}') # 9 answer print(f'9. Collection of film titles grouped in pairs by common genres{answer.group_films_by_genres()}') # 10 answer From 10a9190b097891bc574da17e3f90877275d95c5f Mon Sep 17 00:00:00 2001 From: ValeZh Date: Mon, 21 Aug 2023 13:28:57 +0300 Subject: [PATCH 14/15] all done --- lab2/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lab2/main.py b/lab2/main.py index 0d663d9..58e86d7 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -5,8 +5,6 @@ from copy import deepcopy -# from collections import Counter - class Films: def __init__(self, numb_page): From b9d3217380d3837fa1cc90b673cf38266c3b2390 Mon Sep 17 00:00:00 2001 From: ValeZh Date: Mon, 21 Aug 2023 15:17:03 +0300 Subject: [PATCH 15/15] try to fix conflict --- lab2/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lab2/main.py b/lab2/main.py index 58e86d7..ce25ba8 100644 --- a/lab2/main.py +++ b/lab2/main.py @@ -5,7 +5,6 @@ from copy import deepcopy - class Films: def __init__(self, numb_page): self.header = {