def setUp(self):
        app = Flask(__name__)
        app.config['CASSANDRA_HOSTS'] = ['127.0.0.1']
        app.config['CASSANDRA_KEYSPACE'] = "test1"
        db = CQLAlchemy(app)
        self.User = make_user_model(db)
        create_keyspace_simple("test1", 1)

        self.app = app
        self.db = db
import uuid
from flask import Flask
from flask_cqlalchemy import CQLAlchemy

app = Flask(__name__)
app.config['CASSANDRA_HOSTS'] = ['127.0.0.1']
app.config['CASSANDRA_KEYSPACE'] = "cqlengine"
app.config['CASSANDRA_SETUP_KWARGS'] = {'protocol_version': 3}
db = CQLAlchemy(app)


class address(db.UserType):
    street = db.columns.Text()
    zipcode = db.columns.Integer()


class users(db.Model):
    __keyspace__ = 'cqlengine'
    name = db.columns.Text(primary_key=True)
    addr = db.columns.UserDefinedType(address)
Beispiel #3
0
from alpha_vantage.timeseries import TimeSeries
from flask import Flask, jsonify, request
from flask_cqlalchemy import CQLAlchemy

#Flask setup
app = Flask(__name__)
app.config['CASSANDRA_HOSTS'] = ['cassandra']
app.config['CASSANDRA_KEYSPACE'] = "stocks"
app.config['CQLENG_ALLOW_SCHEMA_MANAGEMENT'] = True
db = CQLAlchemy(app)


class Equity(db.Model):
    equity_name = db.columns.Text(primary_key=True, required=True)
    equity_timestamp = db.columns.List(db.columns.Text, required=False)
    equity_open = db.columns.List(db.columns.Text, required=False)
    equity_high = db.columns.List(db.columns.Text, required=False)
    equity_low = db.columns.List(db.columns.Text, required=False)
    equity_close = db.columns.List(db.columns.Text, required=False)
    equity_volume = db.columns.List(db.columns.Text, required=False)


db.sync_db()


@app.route('/', methods=['GET'])
def get_all_equity_names():
    q = Equity.all()
    count = len(q)
    name = []
    for i in range(count):
Beispiel #4
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_mongoalchemy import MongoAlchemy
from flask_cqlalchemy import CQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245'
app.config[
    'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:mysql@db-mysql:3306/rumi'
app.config['MONGOALCHEMY_DATABASE'] = 'rumi'
app.config['MONGOALCHEMY_SERVER'] = 'db-mongo'
app.config['MONGOALCHEMY_PORT'] = '27017'
app.config['MONGOALCHEMY_SAFE_SESSION'] = 'true'
app.config['CASSANDRA_HOSTS'] = ['db-cassandra']
app.config['CASSANDRA_KEYSPACE'] = "rumi"

db = SQLAlchemy(app)
db2 = MongoAlchemy(app)
db3 = CQLAlchemy(app)
migrate = Migrate(app, db)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'

from rumi_jokes import routes
Beispiel #5
0
from flask_cqlalchemy import CQLAlchemy
from cassandra.cqlengine.management import (create_keyspace_simple)
db = CQLAlchemy()


def init_app(app):
    db.init_app(app)
    create_keyspace_simple(
        app.config['CASSANDRA_KEYSPACE'],
        replication_factor=app.config['CASSANDRA_REPLICATION_FACTOR'])
    db.sync_db()
Beispiel #6
0
##############
DnD App File for Initialisation
Author: Benjamin Smith
Last Edited: 15/04/2020
App Description:
1. Take Users to Registration Page to Sign up to App service
2. Save details in Cassandra Cloud Database and call them to Login
3. Sent User through to Library Page where they can make dynamic requests to external API:
    http://www.dnd5eapi.co/
4. Allow users to create Characters which are then saved to the database
5. Users can check character creations and edit them throughout the campaign
###############
'''

from flask import Flask
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_cqlalchemy import CQLAlchemy

# Initialise app
app = Flask(__name__)
app.config[
    'SECRET_KEY'] = '756ba24325dfc559acf36854910afc59'  # Secret Key for security purposes: (CSRF, {{form.hidden_tag()}}) & Login
app.config['CASSANDRA_HOSTS'] = ['127.0.0.1']
app.config['CASSANDRA_KEYSPACE'] = "main"  # Set database keyspace
bcrypt = Bcrypt(app)  # Initialise hashing framework
login = LoginManager(app)  # Create Login Manager Instances
login.login_view = 'Login'
database = CQLAlchemy(app)  # Create instance of CQLAlchemy database for app

from dndApp import routes
Beispiel #7
0
from cassandra.cluster import Cluster
from flask import Flask
from flask_cqlalchemy import CQLAlchemy

cluster = Cluster()  #C

app = Flask(__name__)
app.config['CASSANDRA_HOSTS'] = ['127.0.0.1']
app.config['CASSANDRA_KEYSPACE'] = "main"
database = CQLAlchemy(app)
'''
session.execute("CREATE KEYSPACE main WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}")
session.set_keyspace('main')

session.execute("CREATE TABLE user(email text PRIMARY KEY, first_name text, last_name text, password text)")

email = '*****@*****.**'
first_name = 'ben'
last_name = 'smith'
password = '******'
session.execute("INSERT INTO user(email, first_name, last_name, password) VALUES(%s, %s, %s, %s)", (email, first_name, last_name, password))


user = session.execute(
            "SELECT email FROM user WHERE (email=%s)", (email.data))

print(user)
'''


class User(database.Model):
Beispiel #8
0
#Imports the python wrapper for Genius Song Lyrics API and authorizes the object with the access token
import lyricsgenius as genius
access_token = 'L1lXyP9PHgtXsIzTM63zqlupMdMZt-LyBwDQ_J1e3CMU4iqsjOxpTSbNpp8gmxx2'
#This is to create and authorized object to make api calls
api = genius.Genius(access_token)

from flask import Flask, jsonify, request
from flask_cqlalchemy import CQLAlchemy

#Flask setup
app = Flask(__name__)
app.config['CASSANDRA_HOSTS'] = ['cassandra']
app.config['CASSANDRA_KEYSPACE'] = "genius"
app.config['CQLENG_ALLOW_SCHEMA_MANAGEMENT'] = True
db = CQLAlchemy(app)

#instance created


#Model definition for the database
class Records(db.Model):
    artists = db.columns.Text(primary_key=True, required=True)
    songs = db.columns.List(db.columns.Text, required=False)
    #lyrics = db.columns.List(db.columns.Text,required=False)


db.sync_db()  #brings everything to the code from db


#Method to get a list of all artists in database
@app.route('/', methods=['GET'])
from flask_cqlalchemy import CQLAlchemy
import uuid

db = CQLAlchemy()  # create a CQLAlchemy wrapper [uses cassandra-driver]


class PII(db.Model):
    uid = db.columns.UUID(primary_key=True, required=True)
    first_name = db.columns.Text(required=True)
    last_name = db.columns.Text(required=True)
    email = db.columns.Text(required=True)
    address = db.columns.Text(required=True)
    mobile = db.columns.Text(required=True)


class User(db.Model):
    uid = db.columns.UUID(primary_key=True, default=uuid.uuid4)
    username = db.columns.Text(partition_key=True, required=True)
    password = db.columns.Text(required=True)
    otp_secret = db.columns.Text()
    otp_enabled = db.columns.Boolean(default=False)
    # boolean for two_way_login confirmation
    tw_login = db.columns.Boolean(default=False)
    # sessions established
    session_estd = db.columns.Boolean(default=False)

    # utype can be internal-A, internal-B, internal-C, external-A, or
    # external-B
    utype = db.columns.Text(required=True, default='external-A')