Esempio n. 1
0
def webhook():
    req = request.get_json()
    # print(req)
    if req['queryResult']['intent']['displayName'] == 'movie ranking':
        rankdata = Mrank()  #movieapi
        result = ''
        count = 1
        for temp in rankdata:
            result = result + str(count) + '위 : ' + temp[
                'title']  # 영화 순위 가져오기.
            if count == 3:
                break
            count += 1
    elif req['queryResult']['intent']['displayName'] == 'movie info - custom':

        movieresult = navermovie(req['queryResult']['queryText'])

        moviedata = movieresult['items'][0]

        return movie_info(
            moviedata['image'],
            moviedata['title'].replace('<b>',
                                       '').replace('</b>',
                                                   ''), moviedata['link'],
            '감독:' + moviedata['director'] + '출연자:' + moviedata['actor'])
    elif req['queryResult']['intent']['displayName'] == 'weather - city':
        wdata = get_wdata(req['queryResult']['queryText'])
        print(wdata)
        return weather_info(wdata)
    elif req['queryResult']['intent'][
            'displayName'] == 'Nshop - custom - custom':
        shopresult = navershop(req['queryResult']['queryText'])
        return shop_info(shopresult['items'])
Esempio n. 2
0
def webhook():
    req = request.get_json()
    if req['queryResult']['intent']['displayName'] =='movie ranking':
        rankdata = Mrank()

        result = ''
        count = 1
        for temp in rankdata:
            result = result + str(count) + '위 : '+temp['title']
            if count==3:
                break
            count += 1
    elif req['queryResult']['intent']['displayName'] =='movie info - custom':
        movieresult = navermovie(req['queryResult']['queryText'])
        moviedata = movieresult['items'][0]


        return movie_info(moviedata['image'],moviedata['title'],moviedata['link'],
                          '감독:'+moviedata['director']+' 출연자'+moviedata['actor'])
    elif req['queryResult']['intent']['displayName'] == 'weather - custom':
        wdata = get_wdata(req['queryResult']['queryText'])
        print(wdata)
        return weather_info(wdata)
    elif req['queryResult']['intent']['displayName'] == 'product - custom':
        sdata = navershop(req['queryResult']['queryText'])
        return shop_infos(sdata['items'])
Esempio n. 3
0
def webhook():
    req = request.get_json()
    print('---------1')
    if req['queryResult']['intent']['displayName'] == 'movie ranking':
        rankdata = Mrank()

        result = ''
        count = 1
        for temp in rankdata:
            result = result + str(count) + '위 : ' + temp['title']
            if count == 3:
                break
            count += 1
    elif req['queryResult']['intent']['displayName'] == 'movie info - custom':

        movieresult = navermovie(req['queryResult']['queryText'])

        moviedata = movieresult['items'][0]

        return movie_info(
            moviedata['image'], moviedata['title'], moviedata['link'],
            '감독:' + moviedata['director'] + ' 출연자' + moviedata['actor'])
    elif req['queryResult']['intent'][
            'displayName'] == 'Weather info - location':
        print('---------2')
        wdata = get_wdata(req['queryResult']['queryText'])
        print('---------3')
        print(wdata)
        return weather_info(wdata)
    elif req['queryResult']['intent']['displayName'] == 'thing info - custom':
        thingresult = navershop(req['queryResult']['queryText'])
        return thing_info(thingresult['items'])
Esempio n. 4
0
def webhook():
    print('웹훅')  #이거나오면 이게 작동한다는 증거

    req = request.get_json()
    #print(req) #잘가져왔는지 확인용.
    if req['queryResult']['intent']['displayName'] == 'movie ranking':
        rankdata = Mrank()
        result = ''
        cnt = 1
        for temp in rankdata:
            result = result + str(cnt) + '위: ' + temp['title'] + "\n "
            print(result)
            if cnt == 3:
                break
            cnt += 1
        return {'fulfillmentText': result}

    elif req['queryResult']['intent']['displayName'] == 'movie info - search':
        movie = navermovie(
            req['queryResult']
            ['queryText'])  #미나리라고 검색한 부분이 여기에 있음. 이걸 검색어로 navermovie함수에 넣어줌
        #print(movie) #잘가져왔는지 확인용.
        moviedata = movie['items'][
            0]  #여기안에 우리가 필요한거 다있다. 젤 먼저 나오는 검색결과를 보여주려고 함.
        #return {'fulfillmentText': '제목:' + moviedata['title']+'감독: '+moviedata['director']+ '출연진: '+moviedata['actor']+ '연도: ' +moviedata['pubDate']}
        return movie_info(
            moviedata['image'], moviedata['title'], moviedata['link'],
            '감독:' + moviedata['director'] + ' 출연자: ' + moviedata['actor'])
    elif req['queryResult']['intent']['displayName'] == 'weather info - city':
        #print(req) 정보가 어디서 들어오는지 확인
        weather = get_wdata(req['queryResult']['queryText'])
        #print(weather)
        return weather_info(weather)
    elif req['queryResult']['intent'][
            'displayName'] == 'naver shopping - search':
        result = navershop(req['queryResult']['queryText'])
        items = result['items']
        item_list = []
        for item in items:
            title = item['title']
            link = item['link']
            image = item['image']
            lprice = item['lprice']
            hprice = item['hprice']
            if hprice == '':
                hprice = lprice
            item_dic = {
                'title': title,
                'link': link,
                'image': image,
                'lprice': lprice,
                'hprice': hprice
            }
            item_list.append(item_dic)
        return shop_info_with_links(item_list)
Esempio n. 5
0
def webhook():
    # print('웹훅')
    req = request.get_json()
    # print(req)

    if req['queryResult']['intent']['displayName'] == 'movie ranking':
        rankdata = Mrank()
        result = ''
        count = 1
        for i in rankdata:
            result = result + str(count) + '위 :' + i['title']
            if count == 3:
                break
            count += 1
        # print(rankdata)

    elif req['queryResult']['intent']['displayName'] == 'movie info_name':
        movieinfo = navermovie(req['queryResult']['queryText'])
        # print(movieinfo)
        moviedata = movieinfo['items'][0]

        return movie_info_img(
            moviedata['image'], moviedata['title'], moviedata['link'],
            '감독:' + moviedata['director'] + ' 출연자' + moviedata['actor'])

    elif req['queryResult']['intent']['displayName'] == 'weather_que_city':
        winfo = get_wdata(req['queryResult']['queryText'])
        # print(winfo)
        return weather_info(winfo)

    # elif req['queryResult']['intent']['displayName'] == 'product_search_name':  #내가 짠 코드(하나만 보여짐)
    #     product = navershop(req['queryResult']['queryText'])
    #     # print(product)
    #     prodata = product['items'][0]
    #     # print(prodata)
    #
    #     return pro_info_img(prodata['image'], prodata['title'], prodata['link'],
    #                         '메이커: ' + prodata['maker'] + ' / 브랜드: ' + prodata['brand'] + ' / 최저가 : ' + prodata['lprice'] + '원')
    #
    elif req['queryResult']['intent'][
            'displayName'] == 'product_search_name':  # 결과물 여러개 나오게 하기
        product = navershop(req['queryResult']['queryText'])
        return shop_infos(product['items'])
Esempio n. 6
0
def Kakaoweather():
    req = request.get_json()

    print(req)
    if req['intent']['name'] == '날씨 지역 블럭':
        print(req['action']['params']['sys_location'])
        result = get_wdata(req['action']['params']['sys_location'])

        imgurl = '맑음 이미지 주소'
        if result['현재일기'] == "":
            imgurl = ''
        elif result['현재일기'] == "구름":
            imgurl = ''

    elif req['intent']['name'] == '영화 정보 블럭':
        result = navermovie("미나리")
        print(result)





    res = {
        "version":"2.0",
        "template":{
            "outputs":[
                {
                   "simpleText" : {"text":result['현재일기']}
                },
                {
                    "simpleImage": {
                        "imageUrl": imgurl,
                        "altText": result['현재일기']
                    }
                }
            ]
        }
    }

    print(res)

    return jsonify(res)
Esempio n. 7
0
def webhook():
    req = request.get_json()
    # print(req)
    if req['queryResult']['intent'][
            'displayName'] == 'movie ranking':  #intent가 movie ranking이라면
        rankdata = collect_movie_data()
        result = ''
        count = 1
        for temp in rankdata:
            result = result + str(count) + '위: ' + temp['title'] + ' '
            if count == 3:
                break
            count += 1
        return {'fulfillmentText': result}

    if req['queryResult']['intent'][
            'displayName'] == 'movie info - input_movie':
        movie_info = navermovie(req['queryResult']['queryText'])
        # movie_info = movie_info['items']
        movie_info = movie_info['items'][0]
        print(movie_info)

        # infos = []
        # for i in movie_info:
        #     movie_title = i['title'].replace('<b>','').replace('</b>','')
        #     subtitle = i['subtitle']
        #     pubDate = i['pubDate']
        #     director = i['director']
        #     actor = i['actor']
        #     userRating = i['userRating']
        #     info = '제목: ' + movie_title + '\n' + '부제: ' + subtitle + '\n' + '개봉: ' + pubDate + '\n' + '감독: ' + director + '\n' + \
        #            '출연: ' + actor + '\n' + '평점: ' + userRating + '\n'
        #     infos.append(info)
        #
        #     print_info = ''
        #     for info in infos:
        #         if infos[-1] != info:
        #             print_info += info + '=================================================================\n'
        #         else:
        #             print_info += info
        # return {'fulfillmentText': print_info}
        return movie_info_with_links(
            movie_info['image'],
            movie_info['title'].replace('<b>',
                                        '').replace('</b>',
                                                    ''), movie_info['link'],
            '감독: ' + movie_info['director'] + ', 출연: ' + movie_info['actor'])

    if req['queryResult']['intent']['displayName'] == 'Weather - region':
        result = get_wdata(req['queryResult']['queryText'])
        return {'fulfillmentText': result}

    if req['queryResult']['intent']['displayName'] == 'Shop - search':
        result = navershop(req['queryResult']['queryText'])
        items = result['items']
        item_list = []
        for item in items:
            title = item['title']
            link = item['link']
            image = item['image']
            lprice = item['lprice']
            hprice = item['hprice']
            if hprice == '':
                hprice = lprice
            item_dic = {
                'title': title,
                'link': link,
                'image': image,
                'lprice': lprice,
                'hprice': hprice
            }
            item_list.append(item_dic)
        return shop_info_with_links(item_list)

    return {'fulfillmentText': '무슨 말인지 모르겠어요.'}
Esempio n. 8
0
def kakaoweather():
    req = request.get_json()
    print(req)
    #날씨 지역 블럭이 들어오면 지역정보만 프린트
    if req['intent']['name'] == '날씨 지역 블록':
        print(req['action']['params']['지역명'])
        result = get_wdata(req['action']['params']['지역명'])
        print(result['현재 일기'])
        imgurl = "https://pbs.twimg.com/profile_images/970346143421906944/mowSlHqs_400x400.jpg"

        if result['현재 일기'] == "맑음" or "":
            res = {
                "version": "2.0",
                "template": {
                    "outputs": [{
                        "simpleText": {
                            "text": result['현재 일기']
                        }
                    }, {
                        "simpleImage": {
                            "imageUrl": imgurl,
                            "altText": "맑음 이미지"
                        }
                    }]
                }
            }

        elif result['현재 일기'] == '구름 많음' or '흐림':
            res = {
                "version": "2.0",
                "template": {
                    "outputs": [{
                        "simpleText": {
                            "text": result['현재 일기']
                        }
                    }, {
                        "simpleImage": {
                            "imageUrl":
                            "https://thumb.ac-illust.com/4f/4f53657bae829388ac54be7f6b6af886_t.jpeg",
                            "altText": "구름많음 이미지"
                        }
                    }]
                }
            }
        elif result['현재 일기'] == '비' or '약한 비 단속적' or '비 끝':
            res = {
                "version": "2.0",
                "template": {
                    "outputs": [{
                        "simpleText": {
                            "text": result['현재 일기']
                        }
                    }, {
                        "simpleImage": {
                            "imageUrl":
                            "https://i.pinimg.com/474x/10/e8/94/10e894ca4d03d3afaf98ece49f429673.jpg",
                            "altText": "비 이미지"
                        }
                    }]
                }
            }
        elif result['현재 일기'] == '연무' or '박무' or '안개 짙어짐' or '안개 옅어짐':
            res = {
                "version": "2.0",
                "template": {
                    "outputs": [{
                        "simpleText": {
                            "text": result['현재 일기']
                        }
                    }, {
                        "simpleImage": {
                            "imageUrl":
                            "https://image.flaticon.com/icons/png/512/2531/2531622.png",
                            "altText": "안개 이미지"
                        }
                    }]
                }
            }
        else:
            res = {
                "version": "2.0",
                "template": {
                    "outputs": [{
                        "simpleText": {
                            "text": result['현재 일기']
                        }
                    }, {
                        "simpleImage": {
                            "imageUrl":
                            "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRz-pkwWFCmE485Lc7tD36zfKRknnOwowB7iH_T_kGAzBlR7rkqP3LHA8m9x1DctbruAv4&usqp=CAU",
                            "altText": "흐린 뒤 맑음이미지"
                        }
                    }, {
                        "basicCard": {
                            "title":
                            "보물상자",
                            "description":
                            "보물상자 안에는 뭐가 있을까",
                            "thumbnail": {
                                "imageUrl":
                                "http://k.kakaocdn.net/dn/83BvP/bl20duRC1Q1/lj3JUcmrzC53YIjNDkqbWK/i_6piz1p.jpg"
                            },
                            "profile": {
                                "imageUrl":
                                "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT4BJ9LU4Ikr_EvZLmijfcjzQKMRCJ2bO3A8SVKNuQ78zu2KOqM",
                                "nickname": "보물상자"
                            },
                            "social": {
                                "like": 1238,
                                "comment": 8,
                                "share": 780
                            },
                            "buttons": [{
                                "action": "message",
                                "label": "열어보기",
                                "messageText": "짜잔! 우리가 찾던 보물입니다"
                            }, {
                                "action":
                                "webLink",
                                "label":
                                "구경하기",
                                "webLinkUrl":
                                "https://e.kakao.com/t/hello-ryan"
                            }]
                        }
                    }, {
                        "basicCard": {
                            "title":
                            "영화순위",
                            "description":
                            "지금 영화 1위는 어떤 영화일까요?",
                            "thumbnail": {
                                "imageUrl":
                                "https://movie.naver.com/movie/bi/mi/basic.nhn?code=187322#"
                            },
                            "profile": {
                                "imageUrl":
                                "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT4BJ9LU4Ikr_EvZLmijfcjzQKMRCJ2bO3A8SVKNuQ78zu2KOqM",
                                "nickname": "보물상자"
                            },
                            "social": {
                                "like": 1238,
                                "comment": 8,
                                "share": 780
                            },
                            "buttons": [{
                                "action": "message",
                                "label": "1위영화",
                                "messageText": "1위영화입니다"
                            }, {
                                "action":
                                "webLink",
                                "label":
                                "예매하기",
                                "webLinkUrl":
                                "https://ticket.movie.naver.com/Ticket/Reserve.aspx"
                            }]
                        }
                    }]
                }
            }
    return jsonify(res)