Esempio n. 1
0
def main():
    """Main part of the movie."""
    print(WELCOME)
    data_file = "movies.csv"
    movies = MovieCollection()
    movies.load_movies(data_file)
    print("{0} movies loaded from {1}".format(movies.movies_num(), data_file))
    while True:
        print(MENU)
        movies.sort("is_watched")
        command = input()
        command = command.lower()
        movies_num = movies.movies_num()
        unwatched_num = movies.watched_num()
        # read the movie from the list

        if command == "l":
            print_inf(movies)

            # input l read the list
        elif command == "a":
            title = input_string("Title: ")
            category = input_string("Category: ")
            year = input_int("Year: ")
            # add movie into movies
            movies.add_movies(Movie(title, category, year))
            print("{}  ({} from {}) added to the movie list".format(
                title, category, year))
            # input a read the "add movies"
        elif command == "m":
            if unwatched_num >= 1:
                print_inf(movies)
                print("Enter the number of a movies to mark as watched")
                while True:
                    sign_num = input_int("")
                    if sign_num > movies_num:
                        print("Invalid number")
                    elif sign_num > unwatched_num:
                        print("That movie is already watched")
                        break
                    else:
                        sign_index = sign_num - 1
                        movie = movies.movies[sign_index]
                        title = movie.title
                        category = movie.category
                        movie.watched()
                        print("{0} in {1} visited!".format(title, category))
                        break
            else:
                print("No more movies to watch!")
                # input m to get the number of wwatched movies and unwatched movies.
        elif command == "q":
            movies.save_movies(data_file)
            print("{0} movies saved to {1}".format(movies_num, data_file))
            print("Thanks for watching")
            break
        else:
            print("Invalid menu choice")
Esempio n. 2
0
class MoviesToWatchApp(App):
    """GUI version of Movie to watch App."""
    def __init__(self, **kwargs):
        """creat the main of the app."""
        super().__init__(**kwargs)
        self.text_attr = DICTIONARY
        self.sort_methods = list(self.text_attr.keys())
        self.sort_current = self.sort_methods[0]
        self.movies = MovieCollection()
        self.movies.load_movies(DATA)
        self.information = WELCOME
        Window.size = (1000, 750)

    def build(self):
        """Build the Kivy GUI."""
        self.title = "Movies to watch"
        self.source = Builder.load_file("app.kv")
        self.button_creat()

        return self.source

    def rank(self, text):
        """sort movies"""
        attr = self.text_attr[text]
        self.movies.sort(attr)
        self.button_creat()

    def button_creat(self):
        """Clear all buttons"""
        self.source.ids.movie_button.clear_widgets()
        for i, movie in enumerate(self.movies.movies):
            temp_button = Button(id=str(i))
            temp_button.bind(on_release=self.movie_button)
            title = movie.title
            year = movie.year
            category = movie.category

            if movie.is_watched:
                watched = " (watched)"
                temp_button.background_color = [1, 1, 1, 1]
            else:
                watched = ""
                temp_button.background_color = button_color
            text = "{} from {},  {} {}".format(title, year, category, watched)
            temp_button.text = text
            # add button to movies_press
            self.source.ids.movie_button.add_widget(temp_button)

    def add_button(self):
        """add movie button."""
        title = self.source.ids.title.text
        year = self.source.ids.year.text
        category = self.source.ids.category.text

        if (title == "") | (year == "") | (category == ""):
            self.information = "All fields must be completed."
            self.bottom_inf()
        else:
            try:
                year = int(year)
                if year < 1:
                    # if the year is less than 1
                    self.information = "Year must be bigger than  0."
                    self.bottom_inf()
                else:
                    movie = Movie(title, year, category)
                    self.movies.add_movies(movie)
                    self.all_inf()
            except ValueError:
                # year is a message
                self.information = "Please input a valid number."
                self.bottom_inf()

    def clear_button(self):
        """What the Clear Button do."""
        self.source.ids.title.text = ""
        self.source.ids.year.text = ""
        self.source.ids.category.text = ""

    def movie_button(self, instance):
        """creat movie button."""
        i = int(instance.id)
        movie = self.movies.movies[i]
        if movie.is_watched:
            movie.unwatch()
            self.information = "You can watch {}.".format(movie.title)
        else:
            movie.watch()
            self.information = "You have watched {}.".format(movie.title)
        self.all_inf()

    def top_inf(self):
        """display the information on the top."""
        self.source.ids.top_message.text = "To watch: {}  Watched: {}".format(
            self.movies.unwatched_num(), self.movies.watched_num())

    def bottom_inf(self):
        """display the information of bottom."""
        self.source.ids.bottom_message.text = self.information

    def all_inf(self):
        """display all information"""
        self.button_creat()
        self.top_inf()
        self.bottom_inf()

    def run_exit(self):
        self.movies.save_movies(DATA)