Example #1
0
def tobs():
    sess = session.Session(bind=engine)
    results = sess.query(Measurement.date, Measurement.tobs).\
                filter(Measurement.date >= "2016-08-23").\
                filter(Measurement.station == "USC00519281")
    sess.close()

    result_list = [{"Date": date, "Temp Obs": tobs} for date, tobs in results]

    return jsonify(result_list)
Example #2
0
def temp_stats_v1(start):
    sess = session.Session(bind=engine)
    results = sess.query(func.min(Measurement.tobs), func.avg(Measurement.tobs), func.max(Measurement.tobs)).\
                filter(Measurement.date >= start)
    sess.close()

    result_list = [{
        "Min Temp": tmin,
        "Max Temp": tmax,
        "Avg Temp": tavg
    } for tmin, tavg, tmax in results]
    return jsonify(result_list)
Example #3
0
def stations():
    sess = session.Session(bind=engine)
    results = sess.query(Station.station,
                         Station.name).group_by(Station.station).all()
    sess.close()

    result_list = [{
        "Station": station,
        "Name": name
    } for station, name in results]

    return jsonify(result_list)
Example #4
0
def precipitation():
    sess = session.Session(bind=engine)
    last_date_obs = sess.query(func.max(Measurement.date)).first()

    prcp_results = sess.query(Measurement.date, Measurement.prcp).\
                filter((Measurement.date <= last_date_obs[0])
              & (Measurement.date > "2016-08-23")).all()

    sess.close()

    prcp_list = [{"Date": date, "Prcp": prcp} for date, prcp in prcp_results]

    return jsonify(prcp_list)
Example #5
0
def main():

    try:
        configure_logging()

        conn = connect_to_db("%s@%s" % (SQL_DB_USER, SQL_DB_HOST), SQL_DB_NAME)
        sess = session.Session(bind=conn)

        # Don't actually define schema
        # Could use an ORM-like framework in the future: https://api.mongodb.com/python/current/tools.html
        client = MongoClient(MONGO_DB_HOST, 27017)

        db = client[MONGO_DB_NAME]
        charity_collection = db[MONGO_DB_COLLECTION]
        charity_collection.create_index("ids.charityId", unique=True)
        charity_collection.create_index("ids.GB-CHC", unique=True)

        lower_limit, upper_limit = get_limits(sess)

        insert_charities(sess, charity_collection, lower_limit, upper_limit)
        update_trustees(sess, charity_collection, lower_limit, upper_limit)
        update_aoo(sess, charity_collection, lower_limit, upper_limit)
        update_causes(sess, charity_collection, lower_limit, upper_limit)
        update_beneficiaries(sess, charity_collection, lower_limit,
                             upper_limit)
        update_operations(sess, charity_collection, lower_limit, upper_limit)
        update_financial(sess, charity_collection, lower_limit, upper_limit)
        update_subsidiaries(sess, charity_collection, lower_limit, upper_limit)
        update_names(sess, charity_collection, lower_limit, upper_limit)

        # TODO:
        # ExtractAcctSubmit, ExtractArSubmit, ExtractPartB
        # ExtractObjects, ExtractRegistration, ExtractRemoveRef
        # ExtractName for subsidiaries
        # Add non-registered charities

    except:
        logging.exception("Unhandled Exception")
Example #6
0
# from All import *
from setting import ENVSetting
import importlib
from sqlalchemy.orm import session
from sqlalchemy.orm import  sessionmaker,session
from sqlalchemy import create_engine


session = session.Session(bind=create_engine(ENVSetting().createConnetionLink()))


def store(modelName, values):
	module = importlib.import_module('database.tables.'+modelName+'Table')
	modelName = getattr(module, modelName)
	print values
	md = modelName(**values)
	session.add(md)
	session.commit()


def get(modelName, values={}):
	# print modelName
	module = importlib.import_module('database.tables.'+modelName+'Table')
	modelName = getattr(module, modelName)
	data = modelName.query.get(**values)
	transformedFilterData = []
	for i in data:
		transformedFilterData.append(i.transform())
	return transformedFilterData

Example #7
0
from os import getenv
from .dbConf import setting
import importlib
from sqlalchemy.orm import session
from sqlalchemy.orm import sessionmaker, session
from sqlalchemy import create_engine

session = session.Session(bind=create_engine(setting))

model_path = getenv('MODEL_PATH')
print("model path -----:> ", model_path)


def store(modelName, values):
    module = importlib.import_module(model_path + '.' + modelName + 'Table')
    modelName = getattr(module, modelName)
    print values
    md = modelName(**values)
    session.add(md)
    session.commit()


def get(modelName, values={}):
    # print modelName
    module = importlib.import_module(model_path + '.' + modelName + 'Table')
    modelName = getattr(module, modelName)
    data = modelName.query.get(**values)
    transformedFilterData = []
    for i in data:
        transformedFilterData.append(i.transform())
    return transformedFilterData