Exemple #1
0
from src.database import db
from lib.flask_restplus import Resource, Namespace, fields, reqparse
from src.main_page import get_main_page

banners = db.collection('banner')

ns_mp = Namespace(name='main-page', description='Main-Page')

res_banners = ns_mp.model(name='banners',
                          model={
                              'title':
                              fields.String(description='배너 제목'),
                              'url_imgs':
                              fields.List(fields.String, description='이미지 URL')
                          })

res_breweries = ns_mp.model(name='breweries',
                            model={
                                'name': fields.String(description='양조장 이름'),
                                'url_img':
                                fields.String(description='양조장 이미지'),
                                'region': fields.String(description='양조장 지역')
                            })

resource = ns_mp.model(name='main-page',
                       model={
                           'banners': fields.List(fields.Nested(res_banners)),
                           'breweries':
                           fields.List(fields.Nested(res_breweries))
                       })
Exemple #2
0
from lib.flask_restplus import Resource, Namespace
from pprint import pprint
from engine.preprocessor.clean import *
from engine.services.talk import *

# from engine.preprocessor.morph import analyze

# chatbot = Chatbot()
ns = Namespace(name='', description='Restful API')

user_input = db.collection('user_input')


@ns.route('/<string:text>')
class Index(Resource):

    @ns.doc('챗봇 입력')
    def get(self, text):
        text = clean(text, token=False)
        ui = UserInput(text=text)
        ret: dict = get_response(ui)

        user_input.add(ui.to_dict())

        return {'answer': ret}, 200
from db.connect import db
from db.rive_qa import RiveQA
from lib.flask_restplus import Resource, Namespace, fields

rive_qa = db.collection('rive_qa')

ns_rive_dummy = Namespace('rive_dummy', description='rive_dummy')

# resource_q = ns_rive_dummy.model(name='q',
#                                  model={'msg': fields.String(example="you can call my <star1> number at 1 (888) 555-5555.", description='사용자 질문 RAW 텍스트'),
#                                         'star*': fields.List(fields.String, description='star1, star2... 에 해당하는 preset string list', example=['happy', 'merry'])})
#
# resource_a = ns_rive_dummy.model(name='q',
#                                  model={'msg': fields.String(example="you can call my <star1> number at 1 (888) 555-5555.", description='사용자 질문 RAW 텍스트'),
#                                         'star*': fields.List(fields.String, description='star1, star2... 에 해당하는 preset string list', example=['happy', 'merry'])})
#
# resource_dummy = ns_rive_dummy.model(
#     name='rive-script-dummy data',
#     model={
#         'q': fields.List(fields.Nested(resource_q))
#     }
# )


@ns_rive_dummy.route('/')
class Route(Resource):

    # @ns_rive_dummy.marshal_with(resource_dummy, as_list=True)
    @ns_rive_dummy.doc('현재 시각을 기준으로 셔틀버스를 조회합니다.')
    def get(self):
        stream = rive_qa.stream()
Exemple #4
0
from lib.flask_restplus import Resource, Namespace, reqparse
from src.detail_page import *
from src.database import db

ns_dp = Namespace(name='detail-page', description='Detail-Page')


@ns_dp.route('/')
class Index(Resource):

    # @ns_dp.marshal_with(resource, as_list=True, code=200, description='메인페이지를 위한 API')
    @ns_dp.doc('브루어리 상세페이지',
               params={
                   'BreweryName': '브루어리 이름',
                   'ContentTypeId': '[관광, 문화시설, 행사, 숙박, 쇼핑, 맛집]'
               })
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('BreweryName',
                            type=str,
                            required=True,
                            help='브루어리 이름')
        parser.add_argument('ContentTypeId', required=False, help='투어 컨텐츠 타입')
        args = parser.parse_args(strict=True)

        # BreweryName으로 브루어리 검색
        brewery = db.collection('brewery').where('name', '==',
                                                 args['BreweryName']).stream()
        try:
            brewery = Brewery.from_dict(next(iter(brewery)).to_dict())
        except StopIteration:
Exemple #5
0
from lib.flask_restplus import Resource, Namespace, reqparse
from engine.services.food import get_recipe, Restaurants
from datetime import datetime
from utils import *

ns_food = Namespace("service/food", description="Service/food")

cache = {}


def _is_corrupted(time: datetime) -> bool:
    now = datetime.now(tz=KST)
    if now.minute - time.minute > 15 or now.day != time.day:
        return True
    return False


def _refresh(restaurant):
    cache[restaurant] = get_recipe(Restaurants[restaurant])
    cache["time"] = datetime.now(KST)
    logger.info(f"refreshed {cache[restaurant]}")


if not is_dev():
    for restaurant in Restaurants:
        _refresh(restaurant.name)


@ns_food.route("/")
class Bus(Resource):
    @ns_food.doc("오늘의 식단을 가져옵니다.",
Exemple #6
0
from lib.flask_restplus import Resource, Namespace
from engine.preprocessor.clean import *
from engine.services.talk import *
from db.connect import client

ns = Namespace(name="", description="Restful API")

user_input = client.collection("user_input")


@ns.route("/<string:text>")
class Index(Resource):
    @ns.doc("챗봇 입력")
    def get(self, text):
        text = clean(text, token=False)
        ui = UserInput(text=text)
        ret: dict = get_response(ui)

        user_input.add(ui.to_dict())

        return {"answer": ret}, 200
Exemple #7
0
from lib.flask_restplus import Resource, Namespace, fields, reqparse
from engine.admin import *

ns_admin_add = Namespace('admin/add', description='질문을 추가 합니다.')


@ns_admin_add.route('/')
class Bus(Resource):
    @ns_admin_add.doc('새로운 질문을 추가합니다.',
                      params={
                          'question': 'question',
                          'answer': 'answer'
                      })
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('answer', type=str, help='answer')
        parser.add_argument('question', type=str, help='question')
        args = parser.parse_args(strict=True)

        question = args.question
        answer = args.answer

        ret = add_qna(question=question, answer=answer)

        if ret:
            return 201
        else:
            return 401
Exemple #8
0
from src.database import db
from lib.flask_restplus import Resource, Namespace, reqparse
from src.models.brewery import Brewery
from utils import logger

banners = db.collection('banner')

ns_b = Namespace(name='brewery', description='Brewery')


@ns_b.route('/')
class Index(Resource):
    @ns_b.doc(
        params={
            'desc': 'desc',
            'available_day': 'available_day',
            'price': 'price',
            'region': 'region',
            'url_apply': 'url_apply',
            'url_logo': 'url_logo',
            'url_img': 'url_img',
            'home_page': 'home_page',
            'location_mapY': 'location_mapY',
            'available': 'available',
            'name': 'name',
            'location_mapX': 'location_mapX'
        })
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('desc', type=str, required=True, help='브루어리 이름')
        parser.add_argument('available_day',
Exemple #9
0
from lib.flask_restplus import Resource, Namespace, reqparse

from engine.admin import *

ns_admin_add = Namespace("admin/add", description="질문을 추가 합니다.")


@ns_admin_add.route("/")
class Bus(Resource):
    @ns_admin_add.doc(
        "새로운 질문을 추가합니다.", params={"question": "question", "answer": "answer"}
    )
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument("answer", type=str, help="answer")
        parser.add_argument("question", type=str, help="question")
        args = parser.parse_args(strict=True)

        question = args.question
        answer = args.answer

        ret = add_qa(question=question, answer=answer)

        if ret:
            return 201
        else:
            return 401
Exemple #10
0
from lib.flask_restplus import Resource, Namespace, fields, reqparse
from engine.services.food import get_recipe, Restaurants
from datetime import datetime
from utils import KST, logger

ns_food = Namespace('service/food', description='Service/food')

cache = {}


def _is_corrupted(time: datetime) -> bool:
    now = datetime.now(tz=KST)
    if now.minute - time.minute > 15 or now.day != time.day:
        return True
    return False


def _refresh(restaurant):
    cache[restaurant] = get_recipe(Restaurants[restaurant])
    cache['time'] = datetime.now(KST)
    logger.info(f'refreshed {cache[restaurant]}')


# for restaurant in Restaurants:
#     _refresh(restaurant.name)


@ns_food.route('/')
class Bus(Resource):
    @ns_food.doc('오늘의 식단을 가져옵니다.',
                 params={'restaurant': '교직원식당, 학생식당, 창의인재원식당, 푸드코트, 창업보육센터'})
from lib.flask_restplus import Resource, Namespace
from flask import request
from src.search import search

ns = Namespace(name='api', description='')


@ns.route('/')
class Route(Resource):
    @ns.doc('', params={'msg': 'message'})
    def get(self):
        msg = request.args.get('msg')
        ret = search(msg)
        return {'data': ret}
Exemple #12
0
from lib.flask_restplus import Resource, Namespace, reqparse, fields
from engine.services.shuttle import ShuttleBus

shuttle_bus = ShuttleBus()
ns_shuttle = Namespace('service/shuttle', description='Service/Shuttle')

station_list = [
    'dorm_cycle', 'dorm_station', 'dorm_artin', 'shuttle_cycle',
    'shuttle_station', 'shuttle_artin', 'station', 'station_artin', 'artin',
    'shuttle_dorm'
]

# station_list = ['dorm_cycle', 'dorm_station', 'dorm_artin', 'shuttle_cycle', 'shuttle_station',
#                 'shuttle_artin', 'station', 'station_artin', 'artin', 'shuttle_dorm']
#
# resource_station = [ns_shuttle.model(name='station', model={
#     'status': fields.Boolean,
#     'minutes': fields.Integer,
#     'seconds': fields.Integer
# }) for station in station_list]
#
# resource_shuttle = ns_shuttle.model(name='shuttle',
#                                     model={station: fields.Nested(resource)
#                                            for station, resource in
#                                            zip(station_list, resource_station)})


@ns_shuttle.route('/')
class Bus(Resource):

    # @ns_shuttle.marshal_with(resource_shuttle, as_list=True)
Exemple #13
0
from engine.services.shuttle import ShuttleBus
from lib.flask_restplus import Resource, Namespace, reqparse, fields

shuttle_bus = ShuttleBus()
ns_shuttle = Namespace("service/shuttle", description="Service/Shuttle")

station_list = [
    "dorm_cycle",
    "dorm_station",
    "dorm_artin",
    "shuttle_cycle",
    "shuttle_station",
    "shuttle_artin",
    "station",
    "station_artin",
    "artin",
    "shuttle_dorm",
]


@ns_shuttle.route("/")
class Bus(Resource):
    @ns_shuttle.doc(
        "현재 시각을 기준으로 셔틀버스를 조회합니다.",
        params={
            "weekend": "평일, 주말",
            "season": "학기중, 계절학기, 방학중",
            "hours": "int",
            "minutes": "int",
            "seconds": "int",
            "now": "bool (기본값: True)",
Exemple #14
0
from lib.flask_restplus import Resource, Namespace

ns = Namespace(name='', description='version-1')


@ns.route('/<param>')
class Index(Resource):
    @ns.doc('Index', params={'param': 'param message'})
    def get(self, param):
        return 'Index Message, param: {}'.format(param)