コード例 #1
0
        Process.run(
            'curl https://servicespub.prod.api.aws.grupokabum.com.br/descricao/v1/descricao/produto/79936 >> %s'
            % file_name)

    ## Save database ##
    # Read $filename
    config_file = './%s' % file_name
    config_helper = ConfigHelper(config_file)
    config = config_helper.load_config()

    # Read only products of config
    config = config['familia']['produtos']
    for data in config:
        product = ProductModel(**data)
        try:
            # Save products in database
            product.save_product()
            sleep(0.01)
        except:
            print({"message": "An error ocurred trying to create product."},
                  500)  # Internal Server Error


api.add_resource(Products, '/produto')
api.add_resource(Product, '/produto/<int:codigo>')

if __name__ == '__main__':
    from sql_alchemy import database
    database.init_app(app)
    app.run(debug=True)
コード例 #2
0
def create_app():
    app = Flask(__name__)
    database.init_app(app)
    return app