def movie_scorepos(event, findm, question): movie_name = checDic(event.message.text) movie_name = searchMovie(movie_name) le = len(checksentence(question)) name = re.sub( '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]', '', movie_name).replace(' ', '') if movie_name != '' and 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'] detail = detail.replace('\n', '') #detail2 = response['response'][0]['allComment'][0]['negativeCount'] if detail != '': return detail else: return 'ยังไม่มีคะแนนด้านบวกครับ' if found == False: return 'ยังไม่มีคะแนนด้านบวกครับ' elif (name == '' and movie_name == '' and le == 1): mov = findm 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'] detail = detail.replace('\n', '') # detail2 = response['response'][0]['allComment'][0]['negativeCount'] if detail != '': return detail else: return 'ยังไม่มีคะแนนด้านบวกครับ' if found == False: return 'ยังไม่มีคะแนนด้านบวกครับ' else: cut = cutw(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'] detail = detail.replace('\n', '') # detail2 = response['response'][0]['allComment'][0]['negativeCount'] if detail != '': return detail else: return 'ยังไม่มีคะแนนด้านบวก' if found == False: return 'ยังไม่มีคะแนนด้านบวก' except: return 'ยังไม่รู้คะแนนเลย' #print(movie_scorepos('อยากได้คะแนนบวกวันเดอวูแมน'))
def movie_enjoy(event, findm, question): dd = checDic(event.message.text) movie_name = searchMovie(dd) e = CutName(question) le = len(checksentence(question)) name = re.sub( '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]', '', movie_name).replace(' ', '') if e != '' and movie_name != '' and 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 le == 1 and name == ''): # คำถามธรรมดา mov = findm 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 'ไม่สนุกมาก' elif movie_name != '' and searchMovieNameInDic(movie_name) != '': with open('new.txt', mode='r', encoding='utf-8-sig') as f: a = load(f) for key, value in a.items(): try: if dd 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 'ไม่รู้นะ' elif 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 e != '' and dd == '': return 'ยังไม่มีข้อมูลนะครับ' else: return 'ยังไม่มีข้อมูลเลยจร้า' #print(movie_enjoy('วันเดอวูแมนสนุกไหมครับ'))
def movie_image(event,findm,question): dd = checDic(event.message.text) movie_name = searchMovie(dd) e = CutName(question) le = len(checksentence(question)) name = re.sub('[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]', '', movie_name).replace(' ', '') if e != '' and movie_name != '' and 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 le == 1 and name == ''): # คำถามธรรมดา mov = findm 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' elif movie_name != '' and searchMovieNameInDic(movie_name) != '': with open('new.txt', mode='r', encoding='utf-8-sig') as f: a = load(f) for key, value in a.items(): try: if dd 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 'ไม่มีรูปเรื่องนี้นะ' elif 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 e !='' and dd =='': return 'ยังไม่มีข้อมูลนะครับ' else: return 'ยังไม่มีข้อมูลเลยจร้า'
def movie_spoil(event,findm,question): dd = checDic(event.message.text) movie_name = searchMovie(dd) e = CutName(question) le = len(checksentence(question)) name = re.sub('[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]', '', movie_name).replace(' ', '') if e != '' and movie_name != '' and 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']['spoilers'] detail = str(detail) detail = detail.replace('/n', '') detail = detail.replace('\n', '') if detail != None: translator = Translator() translations = translator.translate(detail, dest='th') return translations.text else: return 'ยังไม่ทราบส่วนสำคัญเรื่องนี้เลยครับ' if found == False: return 'ยังไม่ทราบตอนจบเรื่องนี้เลยครับ' elif (movie_name == '' and le == 1 and name == ''): # คำถามธรรมดา mov = findm 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']['spoilers'] detail = str(detail) detail = detail.replace('/n','') detail = detail.replace('\n','') if detail != None: translator = Translator() translations = translator.translate(detail, dest='th') return translations.text else: return 'ยังไม่ทราบส่วนสำคัญเรื่องนี้เลยครับ' if found == False: return 'ยังไม่ทราบตอนจบเรื่องนี้เลยครับ' elif movie_name != '' and searchMovieNameInDic(movie_name) != '': with open('new.txt', mode='r', encoding='utf-8-sig') as f: a = load(f) for key, value in a.items(): try: if dd 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']['spoilers'] detail = str(detail) detail = detail.replace('/n', '') detail = detail.replace('\n', '') if detail != None: translator = Translator() translations = translator.translate(detail, dest='th') return translations.text else: return 'ยังไม่ทราบส่วนสำคัญเรื่องนี้เลย' if found == False: return 'ยังไม่ทราบตอนจบเรื่องนี้เลย' except: return 'ยังไม่ข้อมูลเลย' elif 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']['spoilers'] detail = str(detail) detail = detail.replace('/n', '') detail = detail.replace('\n', '') if detail != None: translator = Translator() translations = translator.translate(detail, dest='th') return translations.text else: return 'ยังไม่ทราบส่วนสำคัญเรื่องนี้เลยครับ' if found == False: return 'ยังไม่ทราบตอนจบเรื่องนี้เลยครับ' elif e != '' and dd == '': return 'ยังไม่มีข้อมูลนะครับ' else: return 'ยังไม่มีข้อมูลเลยจร้า' #print(movie_spoil('สปอย','wonderwoman','สปอย'))
def movie_type(event, findm, question): dd = checDic(event.message.text) movie_name = searchMovie(dd) e = CutName(question) le = len(checksentence(question)) name = re.sub( '[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]', '', movie_name).replace(' ', '') if e != '' and movie_name != '' and 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]['Genre'] detail = detail.replace('\n', '') if detail != '': return detail else: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลยครับ' if found == False: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลยครับ' elif (movie_name == '' and le == 1 and name == ''): # คำถามธรรมดา mov = findm 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]['Genre'] detail = detail.replace('\n', '') if detail != '': return detail else: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลยครับ' if found == False: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลยครับ' elif movie_name != '' and searchMovieNameInDic(movie_name) != '': with open('new.txt', mode='r', encoding='utf-8-sig') as f: a = load(f) for key, value in a.items(): try: if dd 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]['Genre'] detail = detail.replace('\n', '') if detail != '': return detail else: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลย' if found == False: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลย' except: return 'ยังไม่ข้อมูลประเภทหนังเลย' elif 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]['Genre'] detail = detail.replace('\n', '') if detail != '': return detail else: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลยครับ' if found == False: return 'ยังไม่รู้วันประเภทหนังเรื่องนี้เลยครับ' elif e != '' and dd == '': return 'ยังไม่มีข้อมูลนะครับ' else: return 'ยังไม่มีข้อมูลเลยจร้า'
def movie_detail(event,findm,question): dd = checDic(event.message.text) movie_name = searchMovie(dd) e = CutName(question) le = len(checksentence(question)) name = re.sub('[กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฝฦใฬมฒท?ื์ิ.่๋้็เโ,ฯี๊ัํะำไๆ๙๘๗๖๕ึ฿ุู๔๓๒๑+ๅาแ]', '', movie_name).replace(' ', '') if e != '' and movie_name != '' and 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(' ','') 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 le == 1 and name == ''): # คำถามธรรมดา mov = findm 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(' ', '') 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(movie_name) != '': with open('new.txt', mode='r', encoding='utf-8-sig') as f: a = load(f) for key, value in a.items(): try: if dd 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(' ', '') 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 'ยังไม่ทราบลยครับ' elif 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(' ', '') 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 e !='' and dd =='': print('เข้า5') return 'ยังไม่มีข้อมูลนะครับ' else: print('เข้า6') return 'ยังไม่มีข้อมูลเลยจร้า' #print(movie_detail('w'))
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()})
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()})