Exemplo n.º 1
0
def movie_image(event, question, userid):
    movie_name = re.sub(
        '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]',
        '', event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                return "https://imagemovie.herokuapp.com/" + movie[
                    'idIMDb'] + '.jpg'

    elif (movie_name == '') and (searchMovieNameInDic(question) == ''):
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ', '')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                return "https://imagemovie.herokuapp.com/" + movie[
                    'idIMDb'] + '.jpg'
    else:
        cut = mmcut(event.message.text)
        with open('new.txt', mode='r', encoding='utf-8-sig') as f:
            a = load(f)
            for key, value in a.items():
                for i in cut:
                    try:
                        if i in value:
                            w = key.lower()
                            movie_name = w.lower()
                            URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
                            r = requests.get(url=URL)
                            data = r.json()
                            found = False
                            for movie in data:
                                if movie_name == movie['nameEN'].lower(
                                ).replace(' ', ''):
                                    found = True
                                    return "https://imagemovie.herokuapp.com/" + movie[
                                        'idIMDb'] + '.jpg'
                    except:
                        return 'ไม่มีรูปเรื่องนี้นะ'
Exemplo n.º 2
0
def movie_director(event, question, userid):
    movie_name = re.sub(
        '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]',
        '', event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                movie_detail = r.json()
                detail = movie_detail['response'][0]['detailMovie'][0][
                    'Direct']
                detail = detail.replace('\n', '')
                if detail != '':
                    return detail
                else:
                    return 'ยังไม่มีข้อมูลผู้กำกับหนังเรื่องนี้เลยครับ'
        if found == False:
            return 'ยังไม่มีข้อมูลผู้กำกับหนังเรื่องนี้เลยครับ'
    elif (movie_name == '') and (searchMovieNameInDic(question) == ''):
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ', '')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                movie_detail = r.json()
                detail = movie_detail['response'][0]['detailMovie'][0][
                    'Direct']
                detail = detail.replace('\n', '')
                if detail != '':
                    return detail
                else:
                    return 'ยังไม่มีข้อมูลผู้กำกับหนังเรื่องนี้เลยครับ'
        if found == False:
            return 'ยังไม่มีข้อมูลผู้กำกับหนังเรื่องนี้เลยครับ'

    else:
        cut = mmcut(event.message.text)
        with open('new.txt', mode='r', encoding='utf-8-sig') as f:
            a = load(f)
            for key, value in a.items():
                for i in cut:
                    try:
                        if i in value:
                            w = key.lower()
                            movie_name = w.lower()
                            URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
                            r = requests.get(url=URL)
                            data = r.json()
                            found = False
                            for movie in data:
                                if movie_name == movie['nameEN'].lower(
                                ).replace(' ', ''):
                                    found = True
                                    Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie[
                                        'idIMDb']
                                    r = requests.get(url=Movie_URL)
                                    movie_detail = r.json()
                                    detail = movie_detail['response'][0][
                                        'detailMovie'][0]['Direct']
                                    detail = detail.replace('\n', '')
                                    if detail != '':
                                        return detail
                                    else:
                                        return 'ยังไม่มีข้อมูลผู้กำกับหนังเรื่องนี้เลย'
                            if found == False:
                                return 'ยังไม่มีข้อมูลผู้กำกับหนังเรื่องนี้เลย'
                    except:
                        return 'ยังไม่รู้ใครเป็นผู้กำกับเลย'
Exemplo n.º 3
0
def movie_enjoy(event, question, userid):
    movie_name = re.sub(
        '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]',
        '', event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/SentimentScore.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                response = r.json()
                detail = response['response'][0]['storyComment'][0][
                    'positiveCount']
                detail2 = response['response'][0]['storyComment'][0][
                    'negativeCount']
                scorepos = int(detail)
                scoreneg = int(detail2)
                pos = ((scorepos / (scorepos + scoreneg)) * 100)
                neg = ((scoreneg / (scoreneg + scorepos)) * 100)

                if pos == neg:
                    return 'เฉยๆนะ'
                if pos >= 50 and pos <= 75:
                    return 'สนุกนะ'
                elif pos >= 76 and pos <= 100:
                    return 'สนุกมาก'
                if neg >= 50 and neg <= 75:
                    return 'ไม่สนุก'
                elif neg >= 76 and neg <= 100:
                    return 'สนุกมาก'

    elif (movie_name == '') and (searchMovieNameInDic(question) == ''):
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ', '')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/SentimentScore.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                response = r.json()
                detail = response['response'][0]['storyComment'][0][
                    'positiveCount']
                detail2 = response['response'][0]['storyComment'][0][
                    'negativeCount']
                scorepos = int(detail)
                scoreneg = int(detail2)
                pos = ((scorepos / (scorepos + scoreneg)) * 100)
                neg = ((scoreneg / (scoreneg + scorepos)) * 100)
                if pos == neg:
                    return 'เฉยๆนะ'
                if pos >= 50 and pos <= 75:
                    return 'สนุก'
                elif pos >= 76 and pos <= 100:
                    return 'สนุกมาก'
                if neg >= 50 and neg <= 75:
                    return 'ไม่สนุกเลย'
                elif neg >= 76 and neg <= 100:
                    return 'ไม่สนุกมาก'

    else:
        cut = mmcut(event.message.text)
        with open('new.txt', mode='r', encoding='utf-8-sig') as f:
            a = load(f)
            for key, value in a.items():
                for i in cut:
                    try:
                        if i in value:
                            w = key.lower()
                            movie_name = w.lower()
                            URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
                            r = requests.get(url=URL)
                            data = r.json()
                            found = False
                            for movie in data:
                                if movie_name == movie['nameEN'].lower(
                                ).replace(' ', ''):
                                    found = True
                                    Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/SentimentScore.php?idmovie=' + movie[
                                        'idIMDb']
                                    r = requests.get(url=Movie_URL)
                                    response = r.json()
                                    detail = response['response'][0][
                                        'storyComment'][0]['positiveCount']
                                    detail2 = response['response'][0][
                                        'storyComment'][0]['negativeCount']
                                    scorepos = int(detail)
                                    scoreneg = int(detail2)
                                    pos = ((scorepos / (scorepos + scoreneg)) *
                                           100)
                                    neg = ((scoreneg / (scoreneg + scorepos)) *
                                           100)
                                    if pos == neg:
                                        return 'ไม่ค่อยนะเฉยๆ'
                                    if pos >= 50 and pos <= 75:
                                        return 'สนุกแน่นอน'
                                    elif pos >= 76 and pos <= 100:
                                        return 'สนุกมากๆเลยนะจะบอกให้'
                                    if neg >= 50 and neg <= 75:
                                        return 'ไม่สนุกเลยครับ'
                                    elif neg >= 76 and neg <= 100:
                                        return 'ไม่สนุกมากๆเลย'

                    except:
                        return 'ไม่รู้นะ'


#print(movie_enjoy('วันเดอวูแมนสนุกไหมครับ'))
Exemplo n.º 4
0
def movie_scoreneg(event, question, userid):
    movie_name = re.sub(
        '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]',
        '', event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/SentimentScore.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                response = r.json()
                #detail = response['response'][0]['allComment'][0]['positiveCount']
                detail2 = response['response'][0]['allComment'][0][
                    'negativeCount']
                detail2 = detail2.replace('\n', '')

                if detail2 != '':
                    return detail2
                else:
                    return 'ยังไม่มีคะแนนด้านลบครับ'
        if found == False:
            return 'ยังไม่มีคะแนนด้านลบครับ'
    elif (movie_name == '') and (searchMovieNameInDic(question) == ''):
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ', '')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/SentimentScore.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                response = r.json()
                # detail = response['response'][0]['allComment'][0]['positiveCount']
                detail2 = response['response'][0]['allComment'][0][
                    'negativeCount']
                detail2 = detail2.replace('\n', '')

                if detail2 != '':
                    return detail2
                else:
                    return 'ยังไม่มีคะแนนด้านลบครับ'
        if found == False:
            return 'ยังไม่มีคะแนนด้านลบครับ'
    else:
        cut = mmcut(event.message.text)
        with open('new.txt', mode='r', encoding='utf-8-sig') as f:
            a = load(f)
            for key, value in a.items():
                for i in cut:
                    try:
                        if i in value:
                            w = key.lower()
                            movie_name = w.lower()
                            URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
                            r = requests.get(url=URL)
                            data = r.json()
                            found = False
                            for movie in data:
                                if movie_name == movie['nameEN'].lower(
                                ).replace(' ', ''):
                                    found = True
                                    Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/SentimentScore.php?idmovie=' + movie[
                                        'idIMDb']
                                    r = requests.get(url=Movie_URL)
                                    response = r.json()
                                    # detail = response['response'][0]['allComment'][0]['positiveCount']
                                    detail2 = response['response'][0][
                                        'allComment'][0]['negativeCount']
                                    detail2 = detail2.replace('\n', '')

                                    if detail2 != '':
                                        return detail2
                                    else:
                                        return 'ยังไม่มีคะแนนด้านลบ'
                            if found == False:
                                return 'ยังไม่มีคะแนนด้านลบ'
                    except:
                        return 'ยังไม่ทราบคะแนน'


#print(movie_scoreneg('คะแนนลบwonderwoman'))
Exemplo n.º 5
0
def movie_review(event, question, userid):
    movie_name = re.sub(
        '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]',
        '', event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/Summarization.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                response = r.json()
                detail = response['response']['Review_mandm']
                detail = detail.replace('\n', '')
                detail = detail.replace('/n', '')

                if detail != None or detail != None:
                    translator = Translator()
                    translations = translator.translate(detail, dest='th')
                    return translations.text
                else:
                    return 'ยังไม่ได้รีวิวหนังเรื่องนี้เลยครับ'
        if found == False:
            return 'ยังไม่ได้รีวิวหนังเรื่องนี้เลยครับ'

    elif (movie_name == '') and (searchMovieNameInDic(question) == ''):
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ', '')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/Summarization.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                response = r.json()
                detail = response['response']['Review_mandm']

                if detail != None or detail != None:
                    translator = Translator()
                    translations = translator.translate(detail, dest='th')
                    return translations.text
                else:
                    return 'ยังไม่ได้รีวิวหนังเรื่องนี้เลยครับ'
        if found == False:
            return 'ยังไม่ได้รีวิวหนังเรื่องนี้เลยครับ'

    else:
        cut = mmcut(event.message.text)
        with open('new.txt', mode='r', encoding='utf-8-sig') as f:
            a = load(f)
            for key, value in a.items():
                for i in cut:
                    try:
                        if i in value:
                            w = key.lower()
                            movie_name = w.lower()
                            URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
                            r = requests.get(url=URL)
                            data = r.json()
                            found = False
                            for movie in data:
                                if movie_name == movie['nameEN'].lower(
                                ).replace(' ', ''):
                                    found = True
                                    Movie_URL = 'http://movieapi.plearnjai.com/DEV/API/Summarization.php?idmovie=' + movie[
                                        'idIMDb']
                                    r = requests.get(url=Movie_URL)
                                    response = r.json()
                                    detail = response['response'][
                                        'Review_mandm']
                                    detail = detail.replace('\n', '')
                                    detail = detail.replace('/n', '')

                                    if detail != None or detail != None:
                                        translator = Translator()
                                        translations = translator.translate(
                                            detail, dest='th')
                                        return translations.text
                                    else:
                                        return 'ยังไม่ได้รีวิวหนังเรื่องนี้เลย'
                            if found == False:
                                return 'ยังไม่ได้รีวิวหนังเรื่องนี้เลย'
                    except:
                        return 'ยังไม่ข้อมูลรีวิวเลย'


#print(movie_review('ขอรีวิวwonderwomanหน่อย'))
#print(movie_review('ขอรีวิววันเดอวูแมนหน่อย'))
Exemplo n.º 6
0
def movie_detail(event,question,userid):
    movie_name = re.sub('[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]','',event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie['idIMDb']
                r = requests.get(url=Movie_URL)
                movie_detail = r.json()
                detail = movie_detail['response'][0]['detailMovie'][0]['Synopsis']
                denew  = detail.replace('&nbsp;','')
                denew= denew.replace('\n','')

                if detail != '':
                    for i in range(0, len(denew)):
                        conv = ord(denew[i])
                        if 161 <= conv <= 251:
                            return denew
                        else:
                            translator = Translator()
                            translations = translator.translate(denew, dest='th')
                            return translations.text
                else:
                    return 'ยังไม่ทราบเนื้อเรื่องนี้เลยครับ'
        if found == False:
            return 'ยังไม่ทราบเนื้อเรื่องนี้เลยครับ'
    elif (movie_name == '') and (searchMovieNameInDic(question) == ''):
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ','')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie['idIMDb']
                r = requests.get(url=Movie_URL)
                movie_detail = r.json()
                detail = movie_detail['response'][0]['detailMovie'][0]['Synopsis']
                denew = detail.replace('&nbsp;', '')
                denew = denew.replace('\n', '')

                if detail != '':
                    for i in range(0, len(denew)):
                        conv = ord(denew[i])
                        if 161 <= conv <= 251:
                            return denew
                        else:
                            translator = Translator()
                            translations = translator.translate(denew, dest='th')
                            return translations.text
                else:
                    return 'ยังไม่ทราบเนื้อเรื่องนี้เลยครับ'
        if found == False:
            return 'ยังไม่ทราบเนื้อเรื่องนี้เลยครับ'
    else:
        cut = mmcut(event.message.text)
        with open('new.txt', mode='r', encoding='utf-8-sig') as f:
            a = load(f)
            for key, value in a.items():
                for i in cut:
                    try:
                        if i in value:
                            w = key.lower()
                            movie_name = w.lower()
                            URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
                            r = requests.get(url=URL)
                            data = r.json()
                            found = False
                            for movie in data:
                                if movie_name == movie['nameEN'].lower().replace(' ', ''):
                                    found = True
                                    Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie['idIMDb']
                                    r = requests.get(url=Movie_URL)
                                    movie_detail = r.json()
                                    detail = movie_detail['response'][0]['detailMovie'][0]['Synopsis']
                                    denew = detail.replace('&nbsp;', '')
                                    denew = denew.replace('\n', '')

                                    if detail != '':
                                        for i in range(0, len(denew)):
                                            conv = ord(denew[i])
                                            if 161 <= conv <= 251:
                                                return denew
                                            else:
                                                translator = Translator()
                                                translations = translator.translate(denew, dest='th')
                                                return translations.text
                                    else:
                                        return 'ยังไม่ทราบเนื้อเรื่องนี้เลย'
                            if found == False:
                                    return 'ยังไม่ทราบเนื้อเรื่องนี้เลย'
                    except :
                        return 'ยังไม่ทราบลยครับ'
#print(movie_detail('ขอเรื่องย่อวันเดอ'))
Exemplo n.º 7
0
def Type(q, event, movie_name, userid, user, question, name):
    if q == 0:  #actor
        if name != '' and q != 9 and q != 8:
            detail = movie_actor(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))
        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_actor(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))
        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_actor(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))
        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": 'Actor',
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": 'Actor',
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": 'Actor',
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": 'Actor',
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })

    if q == 1:  #"director"

        if name != '' and q != 9 and q != 8:
            detail = movie_director(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))
        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_director(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))
        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_director(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))
        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "director",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "director",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "director",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "director",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })

    if q == 2:  #"image"
        if name != '' and q != 9 and q != 8:
            detail = movie_image(event, question, userid)
            image_message = ImageSendMessage(original_content_url=detail,
                                             preview_image_url=detail)
            line_bot_api.push_message(userid, image_message)

        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_image(event, question, userid)
            image_message = ImageSendMessage(original_content_url=detail,
                                             preview_image_url=detail)
            line_bot_api.push_message(userid, image_message)

        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_image(event, question, userid)
            image_message = ImageSendMessage(original_content_url=detail,
                                             preview_image_url=detail)
            line_bot_api.push_message(userid, image_message)

        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "image",
                "Question": question,
                "Answer": 'รูปภาพ' + movie_name,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "image",
                "Question": question,
                "Answer": 'รูปภาพ' + name,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "image",
                "Question": question,
                "Answer": 'รูปภาพ' + movie_name,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "image",
                "Question": question,
                "Answer": 'รูปภาพ' + findmovie(userid),
                "Time": datetime.now()
            })
    if q == 3:  #"review"
        if name != '' and q != 9 and q != 8:
            detail = movie_review(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_review(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_review(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "review",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "review",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "review",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "review",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
    if q == 4:  #"spoil"
        if name != '' and q != 9 and q != 8:
            detail = movie_spoil(event, question, userid)
            print(detail)

            if len(detail) > 1999 and len(detail) < 4000:
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[0:1998]))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail[1999:]))
            elif len(detail) >= 4000:
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[0:1998]))
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[1999:3998]))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail[3999:]))
            elif len(detail) < 2000:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail))

        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_spoil(event, question, userid)
            if len(detail) > 1999 and len(detail) < 4000:
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[0:1998]))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail[1999:]))
            elif len(detail) >= 4000:
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[0:1998]))
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[1999:3998]))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail[3999:]))
            elif len(detail) < 2000:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail))

        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_spoil(event, question, userid)
            if len(detail) > 1999 and len(detail) < 4000:
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[0:1998]))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail[1999:]))
            elif len(detail) >= 4000:
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[0:1998]))
                line_bot_api.reply_message(
                    event.reply_token, TextSendMessage(text=detail[1999:3998]))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail[3999:]))
            elif len(detail) < 2000:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail))

        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "spoil",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "spoil",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "spoil",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "spoil",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })

    if q == 5:  #"detail"
        if name != '' and q != 9 and q != 8:
            detail = movie_detail(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_detail(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_detail(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "detail",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "detail",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "detail",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "detail",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })

    if q == 6:  #"date"

        if name != '' and q != 9 and q != 8:
            detail = movie_date(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_date(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_date(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "date",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "date",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "date",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "date",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })

    if q == 7:  #"type"
        if name != '' and q != 9 and q != 8:
            detail = movie_type(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name != '') and q != 9 and q != 8:
            detail = movie_type(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        elif (name == '') and (movie_name == '') and q != 9 and q != 8:
            detail = movie_type(event, question, userid)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=detail))

        if (name == '') and (movie_name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": movie_name,
                "Cate": "type",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name == '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "type",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        elif (movie_name != '') and (name != ''):
            user.insert({
                "UserId": userid,
                "NameMovie": name,
                "Cate": "type",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
        else:
            user.insert({
                "UserId": userid,
                "NameMovie": findmovie(userid),
                "Cate": "type",
                "Question": question,
                "Answer": detail,
                "Time": datetime.now()
            })
    if q == 8:  #
        if 'สนุก' in question:
            if name != '' and q != 9:
                detail = movie_enjoy(event, question, userid)

                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail))

            elif (name == '') and (movie_name != '') and q != 9:
                detail = movie_enjoy(event, question, userid)

                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail))

            elif (name == '') and (movie_name == '') and q != 9:
                detail = movie_enjoy(event, question, userid)

                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=detail))

            if (name == '') and (movie_name != ''):
                user.insert({
                    "UserId": userid,
                    "NameMovie": movie_name,
                    "Cate": "type",
                    "Question": question,
                    "Answer": detail,
                    "Time": datetime.now()
                })
            elif (movie_name == '') and (name != ''):
                user.insert({
                    "UserId": userid,
                    "NameMovie": name,
                    "Cate": "type",
                    "Question": question,
                    "Answer": detail,
                    "Time": datetime.now()
                })
            elif (movie_name != '') and (name != ''):
                user.insert({
                    "UserId": userid,
                    "NameMovie": name,
                    "Cate": "type",
                    "Question": question,
                    "Answer": detail,
                    "Time": datetime.now()
                })
            else:
                user.insert({
                    "UserId": userid,
                    "NameMovie": findmovie(userid),
                    "Cate": "type",
                    "Question": question,
                    "Answer": detail,
                    "Time": datetime.now()
                })
        elif 'แนะนำหนัง' in question:
            message = TemplateSendMessage(
                alt_text='Carousel template',
                template=CarouselTemplate(columns=[
                    CarouselColumn(
                        thumbnail_image_url=
                        'https://imagemovie.herokuapp.com/tt3501632.jpg',
                        title='this is menu1',
                        text='description1',
                        actions=[
                            PostbackTemplateAction(label='postback1',
                                                   text='postback text1',
                                                   data='action=buy&itemid=1'),
                            MessageTemplateAction(label='message1',
                                                  text='message text1'),
                            URITemplateAction(
                                label='uri1',
                                uri='http://mandm.plearnjai.com/')
                        ]),
                    CarouselColumn(
                        thumbnail_image_url=
                        'https://imagemovie.herokuapp.com/tt3501632.jpg',
                        title='this is menu2',
                        text='description2',
                        actions=[
                            PostbackTemplateAction(label='postback2',
                                                   text='postback text2',
                                                   data='action=buy&itemid=2'),
                            MessageTemplateAction(label='message2',
                                                  text='message text2'),
                            URITemplateAction(
                                label='uri2',
                                uri='http://mandm.plearnjai.com/')
                        ])
                ]))
            line_bot_api.reply_message(event.reply_token, message)
Exemplo n.º 8
0
def checkfunction(event, userid):
    movie_name = re.sub(
        '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]',
        '', event.message.text).replace(' ', '')
    if movie_name != '':
        movie_name = movie_name.lower()
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            print(movie['nameEN'])
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                movie_detail = r.json()
                gen = movie_detail['response'][0]['detailMovie'][0]['Genre']
                date = movie_detail['response'][0]['detailMovie'][0]['Date']
                poster = movie_detail['response'][0]['detailMovie'][0][
                    'Poster']
                direct = movie_detail['response'][0]['detailMovie'][0][
                    'Direct']
                actor = movie_detail['response'][0]['detailMovie'][0]['Actor']
                story = movie_detail['response'][0]['detailMovie'][0][
                    'Synopsis']
                url = 'http://movieapi.plearnjai.com/DEV/API/Summarization.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=url)
                response = r.json()
                review = response['response']['Review_mandm']
                spoil = response['response']['spoilers']
                sum = []
                if actor != '':
                    sum.append('ชื่อนักแสดง ')
                if direct != '':
                    sum.append('ชื่อผู้กำกับ ')
                if poster != '':
                    sum.append('แสดงรูปภาพ ')
                if story != '':
                    sum.append('เรื่องย่อ ')
                if story != '':
                    sum.append('เรื่องย่อ ')
                if date != '':
                    sum.append('ประเภทเรื่อง ')
                if review != '':
                    sum.append('รีวิวหนัง ')
                if spoil != '':
                    sum.append('สปอย ')
                return sum

    if movie_name == '':
        mov = findmovie(userid)
        movie_name = mov.lower().replace(' ', '')
        URL = "http://mandm.plearnjai.com/API/id_nameMovie.php?key=mandm"
        r = requests.get(url=URL)
        data = r.json()
        found = False
        for movie in data:
            print(movie['nameEN'])
            if movie_name == movie['nameEN'].lower().replace(' ', ''):
                found = True
                Movie_URL = 'http://mandm.plearnjai.com/API/detailMovie.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=Movie_URL)
                movie_detail = r.json()
                gen = movie_detail['response'][0]['detailMovie'][0]['Genre']
                date = movie_detail['response'][0]['detailMovie'][0]['Date']
                poster = movie_detail['response'][0]['detailMovie'][0][
                    'Poster']
                direct = movie_detail['response'][0]['detailMovie'][0][
                    'Direct']
                actor = movie_detail['response'][0]['detailMovie'][0]['Actor']
                story = movie_detail['response'][0]['detailMovie'][0][
                    'Synopsis']
                url = 'http://movieapi.plearnjai.com/DEV/API/Summarization.php?idmovie=' + movie[
                    'idIMDb']
                r = requests.get(url=url)
                response = r.json()
                review = response['response']['Review_mandm']
                spoil = response['response']['spoilers']
                sum = []
                if actor != '':
                    sum.append('ชื่อนักแสดง ')
                if direct != '':
                    sum.append('ชื่อผู้กำกับ ')
                if poster != '':
                    sum.append('แสดงรูปภาพ ')
                if story != '':
                    sum.append('เรื่องย่อ ')
                if story != '':
                    sum.append('เรื่องย่อ')
                if date != '':
                    sum.append('ประเภทเรื่อง ')
                if review != '':
                    sum.append('รีวิวหนัง ')
                if spoil != '':
                    sum.append('สปอย ')
                return sum
Exemplo n.º 9
0
def movie(event):

    user = mongo.db.users
    q = event.message.text
    question= normalword(q)
    en =cheEng(question)
    chec = checDic(question)
    chename = searchM(chec)
    find =  checkname(chename)
    ques = checkd(question)
    userid = event.source.user_id
    findm =findmovie(userid)[0]
    ques  =PatternCon(userid,event,findm,ques,user)
    ques = CutNameMovie(ques)
    findcate = findmovie(userid)[1]
    sentence = re.sub('[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]', '',(ques))

    if sentence !='' and searchMovie(question) =='' :
        #cut = cutw(sentence)
        cut = keyword(sentence)

        words = []
        for row in cut:
            words.append(row)
        max = 15
        word = ''
        for line in words:
            cut_len = len(line) - 1
            # print(cut)
            if cut_len >= max:
                max = cut_len

        cut_len = len(cut)
        count1 = max - cut_len
        # word = []
        for line2 in range(count1):
            str = 'PAD'
            words.append(str)
        inputs = {'input': [words], 'cate': [['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']]}
        inputs2 = []
        for poemCount in range(len(inputs['input'])):
            poem = []
            for count in range(15):
                search = inputs['input'][poemCount][count]
                search = search.replace('\ufeff', '')

                if search != 'PAD':
                    # print(search)
                        index = dictionary[search]
                        # [i for i, word in reverse_dictionary.items() if word == search]
                        if index != None:

                            # print(index)
                            poem = np.concatenate((poem, final_embeddings[index]))
                            # print(poem.shape)
                        else:
                            print(search)
                            # print(poem)

                else:
                    poem = np.concatenate((poem, np.zeros(22)))
            inputs2.append(poem)
        graph = tf.Graph()
        with graph.as_default():
            wordCount = 15
            cateDimension = 17
            weightColumn1 = 22
            weightColumn2 = 64
            weightRow = 3
            features1 = 64
            features2 = 64

            sess = tf.InteractiveSession()
            pooled_outputs = []
            x = tf.placeholder(tf.float32, shape=[None, wordCount * weightColumn1])
            y_ = tf.placeholder(tf.float32, shape=[None, cateDimension])
            # y_ = tf.placeholder(tf.float32, shape=[None, cateDimension])
            for i, filter_size in enumerate([2, 3, 4]):
                l2_loss = tf.constant(0.0)
                l2_reg_lambda = 0.0
                with tf.name_scope("conv-maxpool-%s" % filter_size):
                    # Convolution Layer
                    filter_shape = [filter_size, weightColumn1, 1, features1]
                    W = tf.Variable(tf.truncated_normal(filter_shape, stddev=0.1), name="W")
                    b = tf.Variable(tf.constant(0.1, shape=[features1]), name="b")

                    # print(x.get_shape())
                    # print(W.get_shape())
                    x_image = tf.reshape(x, [-1, wordCount, weightColumn1, 1])
                    conv = tf.nn.conv2d(x_image, W, strides=[1, 1, 1, 1], padding='VALID')

                    # Apply nonlinearity

                    h = tf.nn.relu(tf.nn.bias_add(conv, b), name="relu")
                    # Maxpooling over the outputs
                    pooled = tf.nn.max_pool(
                        h,
                        ksize=[1, 15 - filter_size + 1, 1, 1],
                        strides=[1, 1, 1, 1],
                        padding='VALID',
                        name="pool")
                    pooled_outputs.append(pooled)

            # Combine all the pooled features
            num_filters_total = features1 * len([2, 3, 4])
            #print(pooled_outputs)

            # h_pool = tf.concat(3, pooled_outputs)
            h_pool = tf.concat(pooled_outputs, 3)
            h_pool_flat = tf.reshape(h_pool, [-1, num_filters_total])

            # Add dropout
            with tf.name_scope("dropout"):
                keep_prob = tf.placeholder(tf.float32)

                h_drop = tf.nn.dropout(h_pool_flat, keep_prob)

            # Final (unnormalized) scores and predictions
            with tf.name_scope("output"):
                W = tf.get_variable(
                    "W",
                    shape=[num_filters_total, cateDimension],
                    initializer=tf.contrib.layers.xavier_initializer())
                b = tf.Variable(tf.constant(0.1, shape=[cateDimension]), name="b")
                l2_loss += tf.nn.l2_loss(W)
                l2_loss += tf.nn.l2_loss(b)
                # scores = tf.nn.xw_plus_b(h_drop, W, b, name="scores")
                scores = tf.nn.relu(tf.nn.xw_plus_b(h_drop, W, b, name="scores"))
                # predictions = tf.argmax(scores, 1, name="predictions")

            # CalculateMean cross-entropy loss
            with tf.name_scope("loss"):
                losses = tf.nn.softmax_cross_entropy_with_logits(logits=scores, labels=y_)
                loss = tf.reduce_mean(losses) + l2_reg_lambda * l2_loss

            correct_prediction = tf.equal(tf.argmax(scores, 1), tf.argmax(y_, 1))
            train_step = tf.train.AdamOptimizer(1e-4).minimize(losses)  #######///
            accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))  ########///

            saver = tf.train.Saver()  # Gets all variables in `graph`.
            with tf.Session(graph=graph) as sess:
                saver.restore(sess, 'model.ckpt')
                p = sess.run(tf.argmax(scores, 1), feed_dict={x: inputs2, keep_prob: 1.0})

            classify = p
            clas = checkcate(classify)
            print(classify)

            name = re.sub('[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]','', question).replace(' ', '')
            #movie_name = searchMovieNameInDic(question)
            le = len(checksentence(question))

            if findm == '' and classify!=12 and classify!=13 and classify!=14 and classify!=11 and classify!=10 and classify!=9 and classify!=8 and name ==''and chec=='' and classify!=15 and classify!=16 :

                if le ==1:
                    if chec == '':
                        text = 'เรื่องอะไรครับ'
                        line_bot_api.reply_message(event.reply_token, TextSendMessage(text=text))
                        user.insert(
                            {"UserId": userid, "NameMovie": "", "Cate": clas, "Question": question, "Answer": text,"Time": datetime.now()})
                else:
                    Type(clas, event, chec, userid, user, question, name, findm)




            elif (name == '') and (chec == '') and classify == 12:

                general(question, event, userid, user)
            else:

                Type(clas, event, chec, userid, user, question,name,findm)

    elif findm == '' and findcate!='12' and chec !='' and findcate!='16' :
        try:

            check = checkname(ques)
            if chec != '' or check==True:
                w = user.find({'UserId':userid}).sort("Time")
                q = []
                t=[]
                for i in w:
                    a = i
                    for key, value in a.items():
                        if key == 'Question':
                            q.append(value)
                        if key =='Cate':
                            t.append(value)


                ques = q[-1]+chec
                Type(t[-1], event, chec, userid, user, ques, chec,findm)
        except:
            question = 'รีวิวหน่อย'
            detail ='แล้วต้องการอ่าน บทรีวิว ไหมล่ะ'
            line_bot_api.reply_message(event.reply_token,TextSendMessage(text=detail))
            user.insert(
                {"UserId": userid, "NameMovie": chec, "Cate": '', "Question": question, "Answer": detail,
                 "Time": datetime.now()})

    elif findm == '' and find == False and  en=='find':

        line_bot_api.reply_message(event.reply_token, TextSendMessage(text='ไม่มีหนังเรื่องนี้'))
    elif find ==False and en=='find':
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text='พูดภาษาอังกฤษด้วยเก่งจัง'))
    elif find == False and en == 'not':
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text='อย่าพิมภาษาอังกฤษมั่วดิ'))
    elif find == True:

        detail ='ต้องการอ่านเนื้อหาหนังเรื่องนี้ไหมครับ'
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))
        user.insert(
            {"UserId": userid, "NameMovie":chec , "Cate": '5', "Question": chec, "Answer": detail,
             "Time": datetime.now()})
Exemplo n.º 10
0
def Type(clas, event, chec, userid, user, question,name,findm):
    moviename = searchMovie(chec)
    if clas == '0' : #actor
        if name != '' :
            detail = movie_actor(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))
        elif (name == '') and (chec != '') :
            detail = movie_actor(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))
        elif (name == '') and (chec == ''):
            detail = movie_actor(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        if (name =='')and (chec!='') :
            user.insert(
                {"UserId": userid, "NameMovie": moviename, "Cate": '0', "Question": question, "Answer": detail,
                 "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert(
                {"UserId": userid, "NameMovie": name, "Cate": '0', "Question": question, "Answer": detail,
                 "Time": datetime.now()})
        elif (chec != '') and (name != ''):
            user.insert(
                {"UserId": userid, "NameMovie": moviename, "Cate": '0', "Question": question, "Answer": detail,
                 "Time": datetime.now()})
        else:
            user.insert(
                {"UserId": userid, "NameMovie": findm, "Cate": '0', "Question": question, "Answer": detail,
                 "Time": datetime.now()})

    if clas == '1':#"director"
        if name != '' :
            detail = movie_director(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))
        elif (name == '') and (chec != ''):
            detail = movie_director(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))
        elif (name == '') and (chec == '') :
            detail = movie_director(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))
        if (name =='')and (chec!=''):
            user.insert(
                {"UserId": userid, "NameMovie": moviename, "Cate": '1', "Question": question, "Answer": detail,
                 "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert(
                {"UserId": userid, "NameMovie":  name, "Cate": '1', "Question": question, "Answer": detail,
                 "Time": datetime.now()})
        elif (chec != '') and (name != ''):
            user.insert(
                {"UserId": userid, "NameMovie":  moviename, "Cate": '1', "Question": question, "Answer": detail,
                 "Time": datetime.now()})
        else:
            user.insert(
                {"UserId": userid, "NameMovie": findm, "Cate": '1', "Question": question, "Answer": detail,
                 "Time": datetime.now()})

    if clas == '2':#"image"
        try:
            if name != '' :
                detail = movie_image(event,findm,question)
                image_message = ImageSendMessage(
                    original_content_url=detail,
                    preview_image_url=detail
                )
                line_bot_api.push_message(userid,image_message)

            elif (name == '') and (chec != '') :
                detail = movie_image(event,findm,question)
                image_message = ImageSendMessage(
                    original_content_url=detail,
                    preview_image_url=detail
                )
                line_bot_api.push_message(userid, image_message)

            elif (name == '') and (chec == '') :
                detail = movie_image(event,findm,question)
                image_message = ImageSendMessage(
                    original_content_url=detail,
                    preview_image_url=detail
                )
                line_bot_api.push_message(userid, image_message)
        except:
            detail = movie_image(event, findm, question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))


        if (name =='')and (chec!=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '2', "Question": question,
                         "Answer": 'รูปภาพ'+chec, "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": name, "Cate": '2', "Question": question,
                         "Answer": 'รูปภาพ'+name, "Time": datetime.now()})
        elif (chec !='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '2', "Question": question,
                         "Answer": 'รูปภาพ'+chec, "Time": datetime.now()})
        else:
            user.insert({"UserId": userid, "NameMovie":findm, "Cate": '2', "Question": question,
                         "Answer": 'รูปภาพ'+findm, "Time": datetime.now()})
    if clas == '3':#"review"


        if name != '':
            detail = movie_review(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec != '') :
            detail = movie_review(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec == '') :
            detail = movie_review(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))


        if (name =='')and (chec!=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '3', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": name, "Cate": '3', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec !='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '3', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        else:
            user.insert({"UserId": userid, "NameMovie":findm, '3': "review", "Question": question,
                         "Answer": detail, "Time": datetime.now()})
    if clas == '4': #"spoil"

        if name != '' :
            detail = movie_spoil(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail[0:1998]))
        elif (name == '') and (chec != '') :
            detail = movie_spoil(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail[0:1998]))

        elif (name == '') and (chec == '') :
            detail = movie_spoil(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail[0:1998]))


        if (name =='')and (chec!=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '4', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": name, "Cate": '4', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec !='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '4', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        else:
            user.insert({"UserId": userid, "NameMovie":findm, "Cate": '4', "Question": question,
                         "Answer": detail, "Time": datetime.now()})

    if clas == '5': #"detail"

        if name != '':
            detail = movie_detail(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec != '') :
            detail = movie_detail(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec == '') :
            detail = movie_detail(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        if (name =='')and (chec!=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '5', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": name, "Cate": '5', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec !='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '5', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        else:
            user.insert({"UserId": userid, "NameMovie": findm, "Cate": '5', "Question": question,
                         "Answer": detail, "Time": datetime.now()})

    if clas == '6': #"date"


        if name != '' :
            detail = movie_date(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec != '') :
            detail = movie_date(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec == '') :
            detail = movie_date(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        if (name =='')and (chec!=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '6', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec =='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": name, "Cate": '6', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec !='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '6', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        else:
            user.insert({"UserId": userid, "NameMovie": findm, "Cate":'6', "Question": question,
                         "Answer": detail, "Time": datetime.now()})

    if clas == '7': #"type"
        if name != '' :
            detail = movie_type(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec != '') :
            detail = movie_type(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        elif (name == '') and (chec == '') :
            detail = movie_type(event,findm,question)
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

        if (name =='')and (chec!='') :
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '7', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (clas =='')and(name !=''):
            user.insert({"UserId": userid, "NameMovie": name, "Cate": '7', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        elif (chec != '') and (name != ''):
            user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '7', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
        else:
            user.insert({"UserId": userid, "NameMovie": findm, "Cate": '7', "Question": question,
                         "Answer": detail, "Time": datetime.now()})
    if clas == '8':
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text='เราสามารถถาม เกี่ยวกับ ผู้กำกับ นักแสดง รีวิว สปอย แนะนำหนัง รูปภาพ เวลาฉาย ประเภท ของหนังแต่ละเรื่องได้นะได้นะ'))

    if clas == '9':
        message = TemplateSendMessage(
                alt_text='Carousel template',
                template=CarouselTemplate(
                    columns=[
                        CarouselColumn(
                            title='ตัวอย่างการสนทนาในแต่ละประเภท',
                            text='ถามเกี่ยวกับ',
                            actions=[

                                MessageTemplateAction(
                                    label='นักแสดง',
                                    text='ใครเป็นนักแสดง wonderwoman'
                                ),
                                MessageTemplateAction(
                                    label='ผู้กำกับ',
                                    text='ใครเป็นผู้กำกับวันเดอวูแมน'
                                ),
                                MessageTemplateAction(
                                    label='รูปภาพ',
                                    text='อยากดูรูปภาพwonderwoman'
                                )

                            ]
                        ),
                        CarouselColumn(
                            title='ตัวอย่างการสนทนาในแต่ละประเภท',
                            text='ถามเกี่ยวกับ',
                            actions=[

                                MessageTemplateAction(
                                    label='รีวิว',
                                    text='อยากอ่านรีวิวwonderwoman'
                                ),
                                MessageTemplateAction(
                                    label='สปอย',
                                    text='อยากดูสปอยwonderwoman'
                                ),
                                MessageTemplateAction(
                                    label='เรื่องย่อภาพยนตร์',
                                    text='อยากอ่านเรื่องย่อwonderwoman'
                                )
                            ]
                        ),
                        CarouselColumn(
                            title='ตัวอย่างการสนทนาในแต่ละประเภท',
                            text='ถามเกี่ยวกับ',
                            actions=[

                                MessageTemplateAction(
                                    label='ประเภทหนัง',
                                    text='wonderwonเป็นหนังประเภทอะไร'
                                ),
                                MessageTemplateAction(
                                    label='วันฉายภาพยนตร์',
                                    text='wonderwomanฉายวันไหน'
                                ),
                                MessageTemplateAction(
                                    label='ความสนุก',
                                    text='wonderwomanสนุกไหม'
                                )
                            ]
                        ),
                        CarouselColumn(
                            title='ตัวอย่างการสนทนาในแต่ละประเภท',
                            text='ถามเกี่ยวกับ',
                            actions=[

                                MessageTemplateAction(
                                    label='แนะนำภาพยนตร์',
                                    text='แนะนำหนังหน่อย'
                                ),
                                MessageTemplateAction(
                                    label='การทักทายทั่วไป',
                                    text='สบายดีไหม'
                                ),
                                MessageTemplateAction(
                                    label='-',
                                    text='-'
                                )

                            ]
                        )
                    ]
                )
            )
        line_bot_api.reply_message(event.reply_token, message)



    if clas =='10':
            a = []
            d = []
            f = []
            for i in range(6):
                b = searchpic()[0]
                a.append(b)
                c = searchpic()[1]
                d.append(c)
                e = searchpic()[2]
                f.append(e)

            message = TemplateSendMessage(
                alt_text='Carousel template',
                template=CarouselTemplate(
                    columns=[
                        CarouselColumn(
                            thumbnail_image_url=a[0],
                            title=d[0],
                            text=f[0],
                            actions=[
                                MessageTemplateAction(
                                    label='เรื่องย่อ',
                                    text='เรื่องย่อ'+(d[0])
                                ),
                                MessageTemplateAction(
                                    label='บทรีวิว',
                                    text='บทรีวิว'+(d[0])
                                ),
                                URITemplateAction(
                                    label='website',
                                    uri='http://mandm.plearnjai.com/'
                                )
                            ]
                        ),
                        CarouselColumn(
                            thumbnail_image_url=a[1],
                            title=d[1],
                            text=f[1],
                            actions=[
                                MessageTemplateAction(
                                    label='เรื่องย่อ',
                                    text='เรื่องย่อ'+(d[1])
                                ),
                                MessageTemplateAction(
                                    label='บทรีวิว',
                                    text='บทรีวิว'+(d[1])
                                ),
                                URITemplateAction(
                                    label='website',
                                    uri='http://mandm.plearnjai.com/'
                                )
                            ]
                        ),
                        CarouselColumn(
                            thumbnail_image_url=a[2],
                            title=d[2],
                            text=f[2],
                            actions=[
                                MessageTemplateAction(
                                    label='เรื่องย่อ',
                                    text='เรื่องย่อ'+(d[2])
                                ),
                                MessageTemplateAction(
                                    label='บทรีวิว',
                                    text='บทรีวิว'+(d[2])
                                ),
                                URITemplateAction(
                                    label='website',
                                    uri='http://mandm.plearnjai.com/'
                                )
                            ]
                        ),
                        CarouselColumn(
                            thumbnail_image_url=a[3],
                            title=d[3],
                            text=f[3],
                            actions=[
                                MessageTemplateAction(
                                    label='เรื่องย่อ',
                                    text='เรื่องย่อ'+(d[3])
                                ),
                                MessageTemplateAction(
                                    label='บทรีวิว',
                                    text='บทรีวิว'+(d[3])
                                ),
                                URITemplateAction(
                                    label='website',
                                    uri='http://mandm.plearnjai.com/'
                                )
                            ]
                        ),
                        CarouselColumn(
                            thumbnail_image_url=a[4],
                            title=d[4],
                            text=f[4],
                            actions=[
                                MessageTemplateAction(
                                    label='เรื่องย่อ',
                                    text='เรื่องย่อ'+(d[4])
                                ),
                                MessageTemplateAction(
                                    label='บทรีวิว',
                                    text='บทรีวิว'+(d[4])
                                ),
                                URITemplateAction(
                                    label='website',
                                    uri='http://mandm.plearnjai.com/'
                                )
                            ]
                        )

                    ]
                )
            )
            line_bot_api.reply_message(event.reply_token, message)


            return 0
    if clas =='11':
            if name != '' and clas != 9 :
                detail = movie_enjoy(event,findm,question)

                line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

            elif (name == '') and (chec != '') :
                detail = movie_enjoy(event,findm,question)

                line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

            elif (name == '') and (chec == '') :
                detail = movie_enjoy(event,findm,question)

                line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail))

            if (name =='')and (chec!='') :
                user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '8', "Question": question,
                             "Answer": detail, "Time": datetime.now()})
            elif (chec =='')and(name !=''):
                user.insert({"UserId": userid, "NameMovie": name, "Cate": '8', "Question": question,
                             "Answer": detail, "Time": datetime.now()})
            elif (chec != '') and (name != ''):
                user.insert({"UserId": userid, "NameMovie": moviename, "Cate": '8', "Question": question,
                             "Answer": detail, "Time": datetime.now()})
            else:
                user.insert({"UserId": userid, "NameMovie": findmovie(userid), "Cate": '8', "Question": question,
                             "Answer": detail, "Time": datetime.now()})
    if clas == '13':
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text='อย่าพิมพ์มั่วดิ'))
    if clas == '14':
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text='พิมพ์มาใหม่'))
    if clas == '15':  #
        detail = checkmoiveEn()
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text=detail[0:1999]))
        user.insert(
            {"UserId": userid, "NameMovie": findm, "Cate": '15', "Question": question, "Answer": detail,
             "Time": datetime.now()})

    if clas == '16':
        if findm!='':
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text=findm))
            user.insert(
                {"UserId": userid, "NameMovie": findm, "Cate": '16', "Question": question, "Answer": findm,
                 "Time": datetime.now()})
        else:
            detail ='ยังไม่ได้พูดถึงเรื่องไหนเลยนะ'
            line_bot_api.reply_message(event.reply_token, TextSendMessage(text='ยังไม่ได้พูดถึงเรื่องไหนเลยนะ'))
            user.insert(
                {"UserId": userid, "NameMovie": '', "Cate": '16', "Question": question, "Answer": detail,
                 "Time": datetime.now()})