Пример #1
0
def movies_index():
    # Take the search value parameter
    search_value = request.args.get('movie_name')
    search_value = search_value if search_value is not None else ''

    rv_movies = requests.get(MOVIE + "movie/get")

    if rv_movies.status_code != 200:
        return render_template('movie/index.html', movie_list=None)
    rv_json = rv_movies.json()
    movies = rv_json['movies']
    movie_list = []

    for movie in movies:
        my_cast = []

        cast_rv = requests.get(MOVIE + "movie/get/" + str(movie['movie_id']) +
                               "/cast")
        cast_json = cast_rv.json()

        if cast_rv.status_code == 200:
            for actor in cast_json['cast']:
                my_cast.append(Actor(actor['name']))

            movie_list.append(Movie(*take_movie_from_json(movie), my_cast))

    movie_list = [
        movie for movie in movie_list
        if search_value.lower() in movie.title.lower()
    ]
    return render_template('movie/index.html', movie_list=movie_list)
Пример #2
0
def cart():
    if not current_user.is_authenticated:
        return redirect(url_for('site.home'))

    response = requests.get(PAYMENT + "cart/get/" + str(current_user.id))
    if response.status_code != 200:
        return redirect(url_for('site.cart'))
    res_json = json.loads(response.content)

    cart_list = []
    for item in res_json['item_list']:
        # Send to the movie database get movies add them to cart element
        movie_id = item['movie_id']
        print(item)

        movie_info_request = requests.get(MOVIE + 'movie/get/' + str(movie_id))
        movie_info = movie_info_request.json()
        movie = movie_info['movie']

        actor_list = []
        cast_rv = requests.get(MOVIE + "movie/get/" + str(movie_id) + "/cast")
        cast_json = cast_rv.json()

        if cast_rv.status_code == 200:
            for actor in cast_json['cast']:
                actor_list.append(Actor(actor['name']))

        print(actor_list)
        movie = Movie(*take_movie_from_json(movie), Cast(actor_list))

        cart_list.append(
            CartElement(movie, item['duration'], int(float(item['price']))))

    return render_template('cart/index.html', cart_list=cart_list)
Пример #3
0
def movie_watch(movie_id):
    # Get current movie infos
    # CHECK IF USER CAN REALLY WATCH THE MOVIE FROM DATABASE
    if not current_user.is_authenticated:
        return redirect(url_for('site.home'))
    response = requests.get(PAYMENT + "payment/rent/get/" +
                            str(current_user.id))
    if response.status_code != 200:
        return redirect(url_for('site.library'))
    res_json = json.loads(response.content)
    flag = False
    for movie in res_json['movies_list']:
        if movie['movie_id'] == str(movie_id):
            flag = True

    if not flag:
        return redirect(url_for('site.library'))

    movie_info_request = requests.get(MOVIE + 'movie/get/' + str(movie_id))
    print(movie_info_request)
    movie_info = movie_info_request.json()
    movie_info = movie_info['movie']
    my_movie = Movie(*take_movie_from_json(movie_info), None)

    return render_template('watch/index.html', movie=my_movie)
Пример #4
0
    def refresh(self, movieList):
        self.clear()

        downloadDataList = []
        movieObjects = []

        for file in movieList:
            movie = Movie(file)
            movieObjects.append(movie)

            if not movie.data:
                downloadDataList.append(movie)

        for m in sorted(movieObjects,
                        key=lambda movieObject: movieObject.releaseDate,
                        reverse=True):
            posterItem = PosterItem(m, self)

        if downloadDataList:
            self.GetInfo.setMovies(downloadDataList)
Пример #5
0
def read_file(file):
    with open("files/" + file) as f:
        data = json.loads(f.read())

    for i in range(0, len(data)):
        type = data[i]['type']
        if type == 'song':

            result = Song(data[i]['data'])
            ses.add(result)

        elif type == "app":

            result = App(data[i]['data'])
            ses.add(result)

        elif type == "movie":

            result = Movie(data[i]['data'])
            ses.add(result)

        ses.commit()
Пример #6
0
def movies_show(movie_id):

    # TODO: Change this with db by using movie_id

    movie_info_request = requests.get(MOVIE + 'movie/get/' + str(movie_id))
    movie_info = movie_info_request.json()
    movie = movie_info['movie']

    actor_list = []

    cast_rv = requests.get(MOVIE + "movie/get/" + str(movie_id) + "/cast")
    cast_json = cast_rv.json()

    if cast_rv.status_code == 200:
        for actor in cast_json['cast']:
            actor_list.append(Actor(actor['name']))

        print(actor_list)
        movie = Movie(*take_movie_from_json(movie), Cast(actor_list))

        return render_template('movie/show.html', movie=movie)
    return redirect(url_for('site.home'))
Пример #7
0
def library():
    if not current_user.is_authenticated:
        return redirect(url_for('site.home'))

    response = requests.get(PAYMENT + "payment/rent/get/" +
                            str(current_user.id))
    if response.status_code != 200:
        return redirect(url_for('site.home'))

    res_json = json.loads(response.content)
    print(res_json)

    owned_movie_id_list = []
    my_movie_list = []
    for movie in res_json['movies_list']:
        owned_movie_id_list.append(movie['movie_id'])

    print(owned_movie_id_list)
    for movie_id in owned_movie_id_list:
        my_cast = []
        print(MOVIE + 'movie/get/' + str(movie_id))
        movie_info_request = requests.get(MOVIE + 'movie/get/' + str(movie_id))
        print(movie_info_request)
        movie_info = movie_info_request.json()
        movie_info = movie_info['movie']

        cast_rv = requests.get(MOVIE + "movie/get/" +
                               str(movie_info['movie_id']) + "/cast")
        cast_json = cast_rv.json()
        print(cast_json)
        if cast_rv.status_code == 200:
            for actor in cast_json['cast']:
                my_cast.append(Actor(actor['name']))

            my_movie_list.append(
                Movie(*take_movie_from_json(movie_info), my_cast))

    return render_template('library/index.html', movie_list=my_movie_list)
Пример #8
0
def payment():
    if not current_user.is_authenticated:
        return redirect(url_for('site.home'))
    if request.method == 'GET':
        response = requests.get(PAYMENT + "cart/get/" + str(current_user.id))
        if response.status_code != 200:
            return redirect(url_for('site.cart'))
        res_json = json.loads(response.content)

        cart_list = []
        for item in res_json['item_list']:
            # Send to the movie database get movies add them to cart element
            movie_id = item['movie_id']
            print(item)

            movie_info_request = requests.get(MOVIE + 'movie/get/' +
                                              str(movie_id))
            movie_info = movie_info_request.json()
            movie = movie_info['movie']

            actor_list = []
            cast_rv = requests.get(MOVIE + "movie/get/" + str(movie_id) +
                                   "/cast")
            cast_json = cast_rv.json()

            if cast_rv.status_code == 200:
                for actor in cast_json['cast']:
                    actor_list.append(Actor(actor['name']))

            print(actor_list)
            movie = Movie(*take_movie_from_json(movie), Cast(actor_list))

            cart_list.append(
                CartElement(movie, item['duration'],
                            int(float(item['price']))))

        return render_template('payment/index.html',
                               form=None,
                               cart_list=cart_list)
    else:
        form = request.form
        form.data = {}
        form.errors = {}

        print(form['cardholder'])
        print(form['expiration-month'])
        print(form['expiration-year'])
        print(form['cardnumber'])
        print(form['cvc'])
        print(form['price'])

        pay_json = {
            'holder': form["cardholder"],
            'expiration': form["expiration-month"] + form["expiration-year"],
            'number': form["cardnumber"],
            'cvc': form['cvc'],
            'cost': form['price']
        }

        rv = requests.post(PAYMENT + 'payment/pay/' + str(current_user.id),
                           json=pay_json)

        if rv.status_code != 200:
            form.errors[
                'notcompleted'] = 'Payment is not accepted. Please try different card.'
            return render_template('payment/index.html',
                                   form=form,
                                   cart_list=cart_list)
        else:
            return redirect(url_for('site.movies_index'))
Пример #9
0
    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            if self.go == True:  # Running cs sunday
                self.csGame.add_message_to_tracker(message)
            return

        if message.content == 'ping':
            await message.channel.send('pong')

        if message.content.startswith('!god'):
            option = message.content[5:].split(' ')
            if (option[0].lower() == 'help'):
                await message.channel.send(helpMessage)
            if (option[0].lower() == 'dev'):
                devUrl = "https://github.com/Mattmor/Discord-bot"
                await message.channel.send("This is the dev repo: " + devUrl)
            #####################
            # Movie options     #
            #####################
            if (option[0].lower() == 'movie'):
                movieString = ""
                for op in option:
                    if (op != 'movie'):
                        movieString += op + " "
                movie = Movie(movieString)
                await message.channel.send(movie.print_movie())
            #####################
            # Random options    #
            #####################
            if (option[0] == 'choice'):
                await self.random_choice(message)
            if (option[0] == 'flip'):
                await self.coin_flip(message)

        #####################
        # Cs options        #
        #####################
        if message.content.startswith('!cs'):
            option = message.content[4:].split(' ')

            if (option[0] == 'mode'):
                if (len(option) <= 1):  # No mode specified
                    await message.channel.send(
                        "Please specify the mode, Comp or Br")
                else:
                    if (option[1].lower() == "comp"
                            or option[1].lower() == "br"):
                        self.csGame.set_mode(option[1].lower())
                        await message.channel.send("Mode set to: " +
                                                   self.csGame.get_mode(),
                                                   delete_after=10)
                    else:
                        await message.channel.send(
                            "Mode can only be set to comp or br, dumbass")

            if (option[0] == 'randomise'):
                if (len(option) == 1):
                    if (self.go == True):
                        self.csGame.randomise_teams()
                        for message in self.csGame.get_message_tracker():
                            if (message.content.startswith("Final result:")):
                                await message.edit(
                                    content=self.csGame.get_end_message())
                    else:
                        await message.channel.send(
                            "You cant randomise teams before using !cs go")
                elif (option[1] == 'teams'):
                    await self.cs_random_teams(message)

            if (option[0] == 'status'):
                if (self.go == False):
                    await message.channel.send(self.csGame.status())
                else:
                    await message.channel.send(self.csGame.get_end_message())
            if (option[0] == 'start' or option[0] == 'reset'):
                self.csGame.remove_all_messages_from_tracker()
                self.csGame.reset()
                self.go = False
                await message.channel.send("Reset cs game")
            if (option[0] == 'captain' or option[0] == 'captains'):
                if (message.mentions == []):
                    await message.channel.send(
                        "You gotta @ people for caprains")
                else:
                    if (self.go == True):
                        await message.channel.send(
                            "You cant set captains after using !cs go. Please !cs reset before adding new captains"
                        )
                    else:
                        self.csGame.set_captains(message)
                        await message.channel.send("Added captains",
                                                   delete_after=5)
            if (option[0] == 'player' or option[0] == 'players'):
                if (self.go == True):
                    await message.channel.send(
                        "You cant set players after using !cs go. Please !cs reset before adding new players"
                    )
                else:
                    self.csGame.set_players(message)
                    await message.channel.send("Added players", delete_after=5)
            if (option[0] == 'go'):
                canGo = self.csGame.check_all()
                if (canGo == "go" and self.go
                        == False):  ## All set so we can go for comp
                    self.go = True
                    await message.channel.send(self.csGame.get_go_state())
                    captains = self.csGame.get_captains()
                    await message.channel.send(
                        "Current turn: " + str(captains[0].mention)
                    )  # TODO: Change to be crrent captain
                    maps = self.csGame.get_current_maps()
                    for map in maps:
                        await message.channel.send(str(map))
                    trackedMessages = self.csGame.get_message_tracker()
                    for trackedMessage in trackedMessages:
                        for map in maps:
                            if (trackedMessage.content == map):
                                await trackedMessage.add_reaction("🚫"
                                                                  )  # 🚫 ✅

                elif (canGo == "gobr"
                      and self.go == False):  # All set so we can go for br
                    self.csGame.do_br_teams()
                    await message.channel.send(self.csGame.print_br_teams())
                else:  # Check failed so print message
                    if (self.go == True):
                        await message.channel.send(
                            "You have to !cs reset before starting another game"
                        )
                    else:
                        await message.channel.send(canGo)

        if (message.content.lower().startswith('!floor')):
            if (message.guild == self.targetGuild):
                if (message.author.voice != None):
                    floor = message.content[7:]
                    # print("trying to add user...")
                    await self.elevator.add_user(message, floor)
                else:  # User not in a voice channel
                    await message.channel.send(
                        "You need to be connected to a voice channel first.")
            else:  # Not target guild
                logger.info("Error, not target guild")