-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.py
158 lines (130 loc) · 5.05 KB
/
logic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from webscraping import Searching, Scraping
from tkinter import *
import customtkinter
class WatchList:
def __init__(self) -> None:
self.to_watch = []
self.watched = []
self.watching = []
self.search = Searching()
self.scraping = Scraping()
def add_to_watch(self, title):
self.to_watch.append(title)
print(f'Added to watchlist [TO WATCH]: {title}')
def add_to_watching(self, title):
self.watched.append(title)
print(f'Added to watchlist [WATCHING]: {title}')
def add_to_watched(self, title):
self.watching.append(title)
print(f'Added to watchlist [WATCHED]: {title}')
def display_list(self, list_name):
list_map = {
'to_watch': self.to_watch,
'watched': self.watched,
'watching': self.watching
}
if list_name in list_map:
print(f"\n{list_name} list:")
for item in list_map[list_name]:
print(item)
else:
print('Invalid list name')
class Movie:
def __init__(self, title, year, overview, genres, runtime, director, cast, rating) -> None:
self.title = title
self.year = year
self.overview = overview
self.genres = genres
self.runtime = runtime
self.director = director
self.cast = cast
self.rating = rating
def get_details(self):
return {
'Title': self.title,
'Year': self.year,
'Overview': self.overview,
'Genre': self.genres,
'Runtime': self.runtime,
'Director': self.director,
'Cast': ', '.join(self.cast),
'Rating': self.rating
}
class Series:
def __init__(self, title, year, overview, genres, runtime, director, cast, rating) -> None:
self.title = title
self.year = year
self.overview = overview
self.genres = genres
self.runtime = runtime
self.director = director
self.cast = cast
self.rating = rating
def get_details(self):
return {
'Title': self.title,
'Year': self.year,
'Overview': self.overview,
'Genre': self.genres,
'Runtime': self.runtime,
'Director': self.director,
'Cast': ', '.join(self.cast),
'Rating': self.rating
}
class User:
def __init__(self, username, password):
self.username = username
self.password = password
self.watchlist = WatchList()
def check_password(self, password):
return self.password == password
class WatchListManager:
def __init__(self) -> None:
self.watchlist = WatchList()
self.users = {}
def create_account(self, username, password):
if username in self.users:
return False
user = User(username, password)
self.users[username] = user
return True
def login(self, username, password):
user = self.users.get(username)
if user and user.check_password(password):
return user
else:
return None
def run(self, title, list_name, year=None):
print(f"Running search with title: {title}, year: {year}")
search_result = self.watchlist.search.search(title, year)
if search_result:
tmdb_url, search_type = search_result
print(f"Found {search_type} at {tmdb_url}")
details = self.watchlist.scraping.scrape((tmdb_url,))
if details:
title_name, year, overview_text, genres, runtime, director_text, cast_string, rating_text = details
print(f"Scraped details: {details}")
if search_type == 'Movie':
movie = Movie(title_name, year, overview_text, genres, runtime, director_text, cast_string.split(', '), rating_text)
if list_name == 'to_watch':
self.watchlist.add_to_watch(title_name)
elif list_name == 'watching':
self.watchlist.add_to_watching(title_name)
elif list_name == 'watched':
self.watchlist.add_to_watched(title_name)
return movie.get_details()
elif search_type == 'Series':
series = Series(title_name, year, overview_text, genres, runtime, director_text, cast_string.split(', '), rating_text)
if list_name == 'to_watch':
self.watchlist.add_to_watch(title_name)
elif list_name == 'watching':
self.watchlist.add_to_watching(title_name)
elif list_name == 'watched':
self.watchlist.add_to_watched(title_name)
return series.get_details()
else:
print('No result found')
return None
self.watchlist.display_list('to_watch')
self.watchlist.display_list('watching')
self.watchlist.display_list('watched')