Example #1
0
def app(request):
    app = Flask(__name__)
    prefix = uuid4().hex
    app.config['DEBUG'] = True
    app.config['DYNAMO_TABLES'] = [
        make_table('%s-phones' % prefix, 'number', 'N'),
        make_table('%s-users' % prefix, 'username', 'S'),
    ]
    return app
Example #2
0
    def test_settings(self):
        self.assertEqual(len(self.app.config['DYNAMO_TABLES']), 2)
        self.assertEqual(self.app.config['AWS_ACCESS_KEY_ID'], environ.get('AWS_ACCESS_KEY_ID'))
        self.assertEqual(self.app.config['AWS_SECRET_ACCESS_KEY'], environ.get('AWS_SECRET_ACCESS_KEY'))
        self.assertEqual(self.app.config['AWS_REGION'], environ.get('AWS_REGION') or self.dynamo.DEFAULT_REGION)

        # Test DynamoDB local settings.
        app = Flask(__name__)
        app.config['DEBUG'] = True
        app.config['DYNAMO_TABLES'] = [
            Table('%s-phones' % self.prefix, schema=[HashKey('number')]),
            Table('%s-users' % self.prefix, schema=[HashKey('username')]),
        ]
        app.config['DYNAMO_ENABLE_LOCAL'] = True

        self.assertRaises(ConfigurationError, Dynamo, app)

        app.config['DYNAMO_LOCAL_HOST'] = 'localhost'

        self.assertRaises(ConfigurationError, Dynamo, app)

        app.config['DYNAMO_LOCAL_PORT'] = 8000
        self.assertIsInstance(Dynamo(app), object)
Simple server to receive GET requests from pwanalysis.js
and dump all received data into a database.

Author: Angad Gill
"""

from flask import Flask, request, send_file
from flask.ext.dynamo import Dynamo
import dynamodb_config
import time

from multiprocessing import Pool


app = Flask(__name__)
app.config['DYNAMO_TABLES'] = dynamodb_config.DYNAMO_TABLES
dynamo = Dynamo(app)  # Assumes that DynamoDB tables are already setup

process_pool = None

def send_data_to_dynamodb(data):
    """
    Send data to DynamoDB.
    :param data
    :return:
    """
    pagename, time_stamp, user_id = data

    with app.app_context():
        table = dynamo.tables['pages']
        # Update existing pagename value
Example #4
0
from boto.dynamodb2.types import NUMBER
from flask import Flask, render_template, redirect, url_for, request, session, json
from flask.ext.dynamo import Dynamo
from werkzeug import generate_password_hash, check_password_hash
import datetime


# create environment variables
os.environ['AWS_SECRET_ACCESS_KEY'] = "UVMvkydy6RT0VthqxtG/qWwnd2WBd+IVqKvLQOOt"
os.environ['AWS_ACCESS_KEY_ID'] = "AKIAIYIZFUIROGPQQLYQ"

# create the application object
app = Flask(__name__)
app.config['DYNAMO_TABLES'] = [
	Table('users', schema=[HashKey('email')]), 
	Table('requests_incoming', schema=[HashKey('user_id')]), 
	Table('requests_outgoing', schema=[HashKey('user_id')]), 
	Table('requests', schema=[HashKey('request_id')])
]
app.secret_key = 'itissnowingreallyhard'

# create dynamo object
dynamo = Dynamo(app)

# home page
@app.route('/')
def home():
	if session.get('userid'):
		return render_template('newsfeed.html')
	else:
		return render_template('index.html')
Example #5
0
SECURITY_TOGGLE_ON = False

# Read AWS account keys from file
keys = [line.rstrip('\n\r') for line in open('keys.txt')]
session = Session(aws_access_key_id=keys[0],
                  aws_secret_access_key=keys[1],
                  region_name='us-east-1')

# Set up Dynamo
dynamodb = session.resource('dynamodb')
table = dynamodb.Table('students')

# Set up Flask
app = Flask(__name__)
app.config['DYNAMO_TABLES'] = [table]

#==============================================================================
# Database Operations: (C)reate, (R)ead, (U)pdate, (D)elete
#==============================================================================

# Create - Capable of overwrite
def create_item(student):
    table.put_item(
        Item=student
    )
    return student

# Read
def find_item(uid):
    response = table.get_item(
Example #6
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 #7
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);