Example #1
0
from flask import Flask,render_template,request
from flask.ext.login import LoginManager
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.table import Table
from flask_dynamo import Dynamo
import User

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)
Example #2
0
import os, boto, random, string, datetime
from datetime import datetime
from boto.s3.key import Key
from flask import Flask, request, redirect, url_for, render_template
from flask.ext.dynamo import Dynamo
from urllib2 import Request, urlopen, URLError
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.table import Table

#TODO: DYNAMO http://flask-dynamo.readthedocs.org/en/latest/quickstart.html

S3BUCKET = 'isithappeningpictures'

app = Flask(__name__)
app.config['DYNAMO_TABLES'] = [
    Table('Locations', schema=[HashKey('LocationName')]),
    Table('Pictures', schema=[HashKey('PictureId')]),
]

dynamo = Dynamo(app)

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        # Connect to Amazon S3
        data_files = request.files.getlist('file')
		location = request.form['location']
		now = datetime.now().strftime("%Y-%m-%d%H-%M-%S")
		
		fileName = UploadFileToS3(data_files, now)
		CreateLocationFileEntry(location)
		CreatePictureEntry(fileName, now, location);