persistencia = PersistenciaTweets()
        # Manda insertar los tweets en la base de datos
        persistencia.insert_tweets(tweet.values() for tweet in tweets)
        # devuelve un JSON con los tweets y el código de la solicitud
        tweets_bd = persistencia.get_tweets_by_hashtag(
            buscador.to_hashtag(titulo))
        if len(tweets_bd) > 0:
            return tweets_bd, status.HTTP_200_OK
        else:
            return {'message': 'No tweets found'}, status.HTTP_404_NOT_FOUND
    else:
        # Mensaje de error
        error_response = {'message': 'Parámetros incompletos'}
        # Devuelve el mensaje de error y el código de la solicitud
        return error_response, status.HTTP_400_BAD_REQUEST


'''
--------------------------------------------------------------------------------
Ejecución del microservicio
--------------------------------------------------------------------------------
'''

if __name__ == '__main__':
    print '--------------------------------------------------------------------'
    print 'Servicio sv_gestor_tweets'
    print '--------------------------------------------------------------------'
    port = int(os.environ.get('PORT', 8084))
    app.debug = True
    app.run(host='0.0.0.0', port=port)
    error_message = format_error(graphql_error)
    logger.error(error_message)
    return {'error': error_message}, status.HTTP_400_BAD_REQUEST


@app.route('/suco')
def coco():
    return {'data': {'message': 'coco', 'status': '200'}}


@app.route('/health-check')
@app.route('/ping')
def health_check():
    """
    Health check
    """
    return {'reply': 'pong'}


@app.route("/spec")
def spec():
    swag = swagger(app)
    swag['info']['version'] = "1.0"
    swag['info']['title'] = "Demo of graphql API endpoint"
    return swag


if __name__ == '__main__':
    app.debug = app.config['DEBUG']
    app.run(host='0.0.0.0', port=5000)
Beispiel #3
0
    return {"message": "Success!", "success": 1}


# note that backup.csv has fields: [id,title,author,date,content].
@app.route("/update")
@token_auth
def update():
    title = request.data.get("title")
    author = request.data.get("author")
    date = request.data.get("date")
    url = request.data.get("url")
    content = request.data.get("content")
    if content and len(content) > 100:
        with open("backup.csv") as source:
            reader = csv.DictReader(source.read().splitlines())
            # return "number of row: " + str(len(list(reader))) # return the number of rows inside backup.csv, used as next index.
            rowid = str(len(list(reader)))
            newrow = map(toUTF, [rowid, title, author, date, url, content])
            with open("backup.csv", "a") as target:
                writer = csv.writer(target)
                writer.writerow(newrow)
                # return newrow # instead of returning that new post(look redundant), show a successful meg just be fine!
                return "Your post: <" + title + "> has been succesfully uploaded to databased!!!"
    else:
        return "Just a reminder that it's successfully updated, while it won't modify the database for now."


if __name__ == "__main__":
    app.debug = True
    app.run()
    return error_details, status.HTTP_400_BAD_REQUEST


@app.errorhandler(GraphQLError)
def handle_invalid_graph_error(graphql_error):
    error_message = format_error(graphql_error)
    logger.error(error_message)
    return {'error': error_message}, status.HTTP_400_BAD_REQUEST


@app.route('/health-check')
@app.route('/ping')
def health_check():
    """
    Health check
    """
    return {'reply': 'pong'}


@app.route("/spec")
def spec():
    swag = swagger(app)
    swag['info']['version'] = "1.0"
    swag['info']['title'] = "Demo of graphql API endpoint"
    return swag


if __name__ == '__main__':
    app.debug = app.config['DEBUG']
    app.run(host='0.0.0.0', port=5000)