Пример #1
0
# Framework
from bottle import (route, request, response)

# Application modules
from src.db.models import Key
from src.db.mongo import connectMongo
from src.db.storage import Storage

from src.api.jp.weblio import Weblio
from src.api.jp.wordnet import Wordnet
from src.api.jp.jisho import Jisho

from src.run.peon import Peon

# Initialize MongoDB
db = connectMongo()
# Initialize Redis
store = Storage()


@route('/examples/:term')
def get_examples(term):
    """Lookup examples for item in Weblio"""
    term = unicode(term, 'utf-8')
    examples = Weblio().examples(term)
    return {'examples': examples}


@route('/similar/:term')
def get_similar(term):
    """Lookup similar words for item in Weblio"""
Пример #2
0
 def __init__(self, db=None):
     if db:
         self.db = db
     else:
         self.db = connectMongo()
Пример #3
0
# -*- coding: utf-8 -*-

"""
    API routes
"""

# Framework
from bottle import route

# Application modules
from src.db.models import Key
from src.db.mongo import connectMongo
from src.run.peon import Peon

# Initialize MongoDB
db = connectMongo()


@route('/add/:key')
def add_item(key):
    """Add new item"""
    if Peon(db).addItem(key):
        return {'result': 'success'}
    else:
        return {'result': 'failure', 'reason': 'Item is already in DB'}


@route('/del/:key')
def del_item(key):
    """Remove existing item"""
    results = {}