Commit ·
0619723
1
Parent(s): 0cc274a
patch
Browse files- services.py +14 -15
services.py
CHANGED
|
@@ -9,42 +9,41 @@ class RecentList:
|
|
| 9 |
self.sorted_films = []
|
| 10 |
self.sorted_series = []
|
| 11 |
|
| 12 |
-
def add_entry(self, title, year, description, image_link, genres,media_type):
|
| 13 |
if media_type == 'film':
|
| 14 |
self._update_entry(self.films, self.sorted_films, title, year, description, image_link, genres)
|
| 15 |
elif media_type == 'series':
|
| 16 |
self._update_entry(self.series, self.sorted_series, title, year, description, image_link, genres)
|
| 17 |
-
|
| 18 |
def _update_entry(self, dictionary, sorted_list, title, year, description, image_link, genres):
|
| 19 |
try:
|
| 20 |
-
# Convert year to integer
|
| 21 |
year = int(year)
|
| 22 |
except ValueError:
|
| 23 |
raise ValueError(f"Invalid year: {year}. Year must be an integer.")
|
| 24 |
|
| 25 |
if title in dictionary:
|
| 26 |
-
|
| 27 |
-
old_year = dictionary[title][0] # Get the old year
|
| 28 |
try:
|
| 29 |
sorted_list.remove((-old_year, title))
|
| 30 |
except ValueError:
|
| 31 |
-
pass
|
| 32 |
|
| 33 |
-
# Update or add the new entry in the dictionary
|
| 34 |
dictionary[title] = (year, description, image_link, genres)
|
| 35 |
-
|
| 36 |
-
# Insert the new year and title into the sorted list
|
| 37 |
bisect.insort(sorted_list, (-year, title))
|
| 38 |
|
| 39 |
def get_sorted_entries(self, media_type):
|
| 40 |
if media_type == 'film':
|
| 41 |
-
#
|
| 42 |
-
return [
|
|
|
|
|
|
|
|
|
|
| 43 |
elif media_type == 'series':
|
| 44 |
-
#
|
| 45 |
-
return [
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
class GenreList:
|
| 50 |
def __init__(self):
|
|
|
|
| 9 |
self.sorted_films = []
|
| 10 |
self.sorted_series = []
|
| 11 |
|
| 12 |
+
def add_entry(self, title, year, description, image_link, genres, media_type):
|
| 13 |
if media_type == 'film':
|
| 14 |
self._update_entry(self.films, self.sorted_films, title, year, description, image_link, genres)
|
| 15 |
elif media_type == 'series':
|
| 16 |
self._update_entry(self.series, self.sorted_series, title, year, description, image_link, genres)
|
| 17 |
+
|
| 18 |
def _update_entry(self, dictionary, sorted_list, title, year, description, image_link, genres):
|
| 19 |
try:
|
|
|
|
| 20 |
year = int(year)
|
| 21 |
except ValueError:
|
| 22 |
raise ValueError(f"Invalid year: {year}. Year must be an integer.")
|
| 23 |
|
| 24 |
if title in dictionary:
|
| 25 |
+
old_year = dictionary[title][0]
|
|
|
|
| 26 |
try:
|
| 27 |
sorted_list.remove((-old_year, title))
|
| 28 |
except ValueError:
|
| 29 |
+
pass
|
| 30 |
|
|
|
|
| 31 |
dictionary[title] = (year, description, image_link, genres)
|
|
|
|
|
|
|
| 32 |
bisect.insort(sorted_list, (-year, title))
|
| 33 |
|
| 34 |
def get_sorted_entries(self, media_type):
|
| 35 |
if media_type == 'film':
|
| 36 |
+
# Now returns title, year, description, image_link, and genres
|
| 37 |
+
return [
|
| 38 |
+
(title, -year, self.films[title][1], self.films[title][2], self.films[title][3])
|
| 39 |
+
for year, title in self.sorted_films
|
| 40 |
+
]
|
| 41 |
elif media_type == 'series':
|
| 42 |
+
# Now returns title, year, description, image_link, and genres
|
| 43 |
+
return [
|
| 44 |
+
(title, -year, self.series[title][1], self.series[title][2], self.series[title][3])
|
| 45 |
+
for year, title in self.sorted_series
|
| 46 |
+
]
|
| 47 |
|
| 48 |
class GenreList:
|
| 49 |
def __init__(self):
|