Пример #1
0
def init_app(app):
    dynamo = Dynamo(app)
    dynamo.create_all()

    return app
Пример #2
0
logging.getLogger("flask_ask").setLevel(logging.DEBUG)

# DynamoDB config
app.config['DYNAMO_TABLES'] = [
    {
        'TableName': 'buses',
        'KeySchema': [dict(AttributeName='user_id', KeyType='HASH')], 
        'AttributeDefinitions': [dict(AttributeName='user_id', AttributeType='S')],
        'ProvisionedThroughput': dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }
]
dynamo = Dynamo(app)

# create tables if doesn't exist
with app.app_context():
    dynamo.create_all()

@ask.launch
def welcome():

    # check if user already has a saved bus
    response = dynamo.tables['buses'].get_item(Key={'user_id': session.user.userId })

    if 'Item' in response and 'bus_stop' in response['Item']:
        item = response['Item']

        session.attributes['bus_route'] = item['bus_route']
        session.attributes['bus_stop'] = item['bus_stop']
        session.attributes['stop_code'] = item['stop_code']

        return question("Welcome to Find My Bus!")
Пример #3
0
app = Flask(__name__)

app.config['DYNAMO_TABLES'] = [
    Table('users',schema=[HashKey('id')])
]

app.config['DYNAMO_ENABLE_LOCAL'] = True
app.config['DYNAMO_LOCAL_HOST'] = 'localhost'
app.config['DYNAMO_LOCAL_PORT'] = 8000

dynamo = Dynamo(app)

# Create any tables that don't exist yet
with app.app_context():
    dynamo.create_all()

users = Table('users')

login_manager = LoginManager()
login_manager.init_app(app)


def load_user(the_username):
    user_data = users.get_item(username=the_username)
    user = User.User(user_data['username'],user_data['email'],user_data['password'],True)
    return user


@app.route('/',methods=['GET'])
def hello_world():