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
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
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
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
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':[] }
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
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
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.')
# -*- coding: utf-8 -*-