Commit 16a3251a authored by Sarah Abrishami's avatar Sarah Abrishami

WIP: modifications

parent 033ecca1
...@@ -4,9 +4,12 @@ import logging ...@@ -4,9 +4,12 @@ import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from flask import Flask from flask import Flask
from flask_caching import Cache from flask_caching import Cache
from flask_sqlalchemy import SQLAlchemy
# from flask_migrate import Migrate
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from app.config import configs from app.config import configs
db = SQLAlchemy()
cache = Cache() cache = Cache()
...@@ -27,11 +30,14 @@ def create_app(): ...@@ -27,11 +30,14 @@ def create_app():
config_name = os.getenv('FLASK_ENV') or 'default' config_name = os.getenv('FLASK_ENV') or 'default'
app.config.from_object(configs[config_name]) app.config.from_object(configs[config_name])
db.init_app(app)
# migrate.init_app(app, db)
cache.init_app(app) cache.init_app(app)
from app.main import main as main_blueprint from app.main import main as main_blueprint
app.register_blueprint(main_blueprint) app.register_blueprint(main_blueprint)
with app.app_context():
db.create_all()
# if app.config['AUTO_UPDATE']: # if app.config['AUTO_UPDATE']:
# sched = BackgroundScheduler(daemon=True) # sched = BackgroundScheduler(daemon=True)
......
...@@ -7,7 +7,7 @@ class Config: ...@@ -7,7 +7,7 @@ class Config:
DEBUG = False DEBUG = False
TESTING = False TESTING = False
API_DESCRIPTION = 'Broccoli Rule Engine' API_DESCRIPTION = 'Broccoli Rule Engine'
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://postges:postges@10.1.1.5:5432/dqdb_test' SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://postgres:postgres@10.1.1.5:5432/dqdb_test'
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT') LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT')
PORT = 5800 PORT = 5800
......
...@@ -6,4 +6,5 @@ main = Blueprint('main', __name__) ...@@ -6,4 +6,5 @@ main = Blueprint('main', __name__)
CORS(main) CORS(main)
from app.main import errors from app.main import errors
from app.main.views import life_check from app.main.views import life_check, validate
from app import db
import gzip import gzip
import collections import collections
from flask import make_response, json, current_app from flask import make_response, json
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import khayyam as kym
from app.errors import * from app.errors import *
import gc import gc
import requests from rulemall.utils.rule_builder import rule_builder
from app import db
def response_message(data=None, status=200): def response_message(data=None, status=200):
...@@ -55,3 +55,19 @@ def convert(o): ...@@ -55,3 +55,19 @@ def convert(o):
if o is np.ma.masked: if o is np.ma.masked:
return None return None
json.dumps(o) json.dumps(o)
def read_data():
return pd.read_excel('app/main/static/sample_data.xlsx')
def read_rules():
return rule_builder('app/main/static/rule_config.yml')
def write_validations(df, table_name='test2'):
try:
df.to_sql(table_name, con=db.engine, if_exists='replace', index=False)
except Exception as e:
return str(e)
return 'success'
from app.main import main
from app.main.utils.common import response_message
from flask import current_app
@main.route('/', methods=['GET', 'POST'])
def life_check():
return response_message(f'{current_app.config["API_DESCRIPTION"]} API is active!')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment