Example #1
0
def datalayer_1(request):
    
    logger.info('datalayer_1 - METHOD STARTED with parameters: request:%s' % request)
    
    return_data = { 'service':'dataLayer', 'version':1 }
    
    if 'text' not in request.form:
        logger.error('datalayer_1 - ERROR post variable \'text\' not supplied')
        return ERROR_DATALAYER_NOTEXT
    
    text = request.form['text']
    
    return_data = {
        'service':'datalayer',
        'version':1,
        'status':'success'
    }
    
    return_data['datalayer'] = {
        'text':text,
        'tags':run_text_tagging(text),
        'locations':run_text_locations(text),
        'sentiment':run_text_sentiment(text)         
    }
    
    logger.info('datalayer_1 - METHOD ENDED')
    
    return return_data
Example #2
0
def run_text_locations(text):
    locations = []
    
    try:
        locations = yahooplacemaker_adapter(text)
    except Exception, e:
        logger.error('datalayer_1 - ERROR the call the location service failed: %s' % e)
        if not MASK_ERRORS:
            raise e 
Example #3
0
def run_text_sentiment(text):
    sentiment = 0;

    try:
        sentiment = sentiment_adapter(text)
    except Exception, e:
        logger.error('datalayer_1 - ERROR the call the sentiment service failed: %s' % e)
        if not MASK_ERRORS:
            raise e 
Example #4
0
def run_text_tagging(text):
    tags = []
    
    try:
        tags = nlp_adapter(text)
    except Exception, e:
        logger.error('datalayer_1 - ERROR the call the nlp service failed: %s' % e)
        if not MASK_ERRORS:
            raise e 
Example #5
0
def run_img_face(image):
    try:
        objectdetectionface_response = objectdetectionface_adapter(image)
        
        if objectdetectionface_response['status'] == 'success':
            return { 'faces':objectdetectionface_response['faces'] }
        else:
            return { 'faces':[] }
    except Exception, e:
        logger.error(e)
        return { 'faces':[] }
Example #6
0
def testing_get():
    if request.method == 'POST':
        # this will never get triggered because you didn't specify the POST method in the @app.route
        return "never going to show"

    if 'search' not in request.args:
        logger.error("you forgot to pass the search args")
        return "failed."

    search = request.args.get("search")
    logger.info("the search variable is  = " + search)
    return "you made a GET request with a parameter search = " + search
Example #7
0
def testing_get():
    if request.method == "POST":
        # this will never get triggered because you didn't specify the POST method in the @app.route
        return "never going to show"

    if "search" not in request.args:
        logger.error("you forgot to pass the search args")
        return "failed."

    search = request.args.get("search")
    logger.info("the search variable is  = " + search)
    return "you made a GET request with a parameter search = " + search
Example #8
0
def connect(uri):
    """
    Connects to the database at the given uri.
    """
    global db_proxy

    if uri:
        logger.debug('Connected to db:%s.' % uri)
        parsed = urlparse(uri)
        db = PostgresqlDatabase(database=parsed.path[1:],
                                user=parsed.username,
                                password=parsed.password,
                                host=parsed.hostname,
                                autorollback=True)
        db.connect()
        db_proxy.initialize(db)
    else:
        logger.error('Could not connect to the database.')
Example #9
0
# -*- coding: utf-8 -*-