예제 #1
0
파일: cube.py 프로젝트: yenchih/mining
def process(_cube):
    try:
        log_it("START: {}".format(_cube['slug']), "bin-mining")

        mongo = MongoPlugin(uri=conf("mongodb")["uri"],
                            db=conf("mongodb")["db"],
                            json_mongo=True).get_mongo()

        c = CubeProcess(_cube)
        if _cube.get('type') == 'relational':
            c.load()
            c.frame()
            c.save()
        elif _cube.get('type') == 'cube_join':
            c.environment(_cube.get('type'))
            cube_join = CubeJoin(_cube)
            c._data(cube_join.none())
            c._keys(cube_join.none().columns.values)
            c.frame()
            c.save()

    except Exception, e:
        log_it(e, "bin-mining")
        log_it(traceback.format_exc(), "bin-mining")
        _cube['run'] = False
        mongo['cube'].update({'slug': _cube['slug']}, _cube)
예제 #2
0
파일: cube.py 프로젝트: yenchih/mining
    def __init__(self, _cube):

        log_it("START: {}".format(_cube['slug']), "bin-mining")

        self.mongo = MongoPlugin(uri=conf("mongodb")["uri"],
                                 db=conf("mongodb")["db"],
                                 json_mongo=True).get_mongo()

        del _cube['_id']
        self.cube = _cube
        self.slug = self.cube['slug']
예제 #3
0
 def setUp(self):
     self.app = bottle.Bottle(catchall=False)
     read_pref = pymongo.ReadPreference.SECONDARY
     plugin = MongoPlugin(
         uri=
         "mongodb://127.0.0.1:27017,127.0.0.1:27018/?replicaSet=testReplSet",
         db="bottle",
         json_mongo=True,
         read_preference=read_pref,
         w=2)
     self.plugin = self.app.install(plugin)
예제 #4
0
def scheduler_app():
    mongo = MongoPlugin(uri=conf("mongodb")["uri"],
                        db=conf("mongodb")["db"],
                        json_mongo=True).get_mongo()

    for cube in mongo['cube'].find({'scheduler_status': True}):
        rules(cube)

    for dashboard in mongo['dashboard'].find({'scheduler_status': True}):
        elements = [e['id'] for e in dashboard['element']]
        for e in elements:
            element = mongo['element'].find_one({'slug': e})
            cube = mongo['cube'].find_one({'slug': element['cube']})
            rules(cube, dashboard['scheduler_type'],
                  dashboard['scheduler_interval'])

    while True:
        for cube in mongo['cube'].find({'scheduler_status': True}):
            if cube['slug'] not in register:
                rules(cube)

        for dashboard in mongo['dashboard'].find({'scheduler_status': True}):
            elements = [e['id'] for e in dashboard['element']]
            for e in elements:
                element = mongo['element'].find_one({'slug': e})
                cube = mongo['cube'].find_one({'slug': element['cube']})
                if cube['slug'] not in register:
                    rules(cube, dashboard['scheduler_type'],
                          dashboard['scheduler_interval'], dashboard['slug'])

        for cube in mongo['cube'].find({'scheduler_status': False}):
            if cube['slug'] in register:
                schedule.cancel_job(onrun[cube['slug']])
                del onrun[cube['slug']]
                register.remove(cube['slug'])

        for dashboard in mongo['dashboard'].find({'scheduler_status': False}):
            elements = [e['id'] for e in dashboard['element']]
            for e in elements:
                try:
                    element = mongo['element'].find_one({'slug': e})
                    cube = mongo['cube'].find_one({'slug': element['cube']})
                    jobn = u"{}-{}".format(cube['slug'], dashboard['slug'])
                    if jobn in register:
                        schedule.cancel_job(onrun[jobn])
                        del onrun[jobn]
                        register.remove(jobn)
                except:
                    pass

        schedule.run_pending()
        sleep(1)
예제 #5
0
파일: cube.py 프로젝트: yenchih/mining
def run(cube_slug=None):
    mongo = MongoPlugin(uri=conf("mongodb")["uri"],
                        db=conf("mongodb")["db"],
                        json_mongo=True).get_mongo()

    pool = ThreadPool(20)

    for cube in mongo['cube'].find():
        slug = cube['slug']
        if cube_slug and cube_slug != slug:
            continue

        pool.add_task(process, cube)

    pool.wait_completion()
    return True
예제 #6
0
    def __init__(self, _cube):

        log_it("START: {}".format(_cube['slug']), "bin-mining")

        self.mongo = MongoPlugin(uri=conf("mongodb")["uri"],
                                 db=conf("mongodb")["db"],
                                 json_mongo=True).get_mongo()

        MyClient = riak.RiakClient(protocol=conf("riak")["protocol"],
                                   http_port=conf("riak")["http_port"],
                                   host=conf("riak")["host"])

        self.MyBucket = MyClient.bucket(conf("riak")["bucket"])
        self.MyBucket.enable_search()
        del _cube['_id']
        self.cube = _cube
        self.slug = self.cube['slug']
예제 #7
0
from bottle import Bottle, request, response
from bottle import run
from bottle.ext.mongo import MongoPlugin
import datetime
from bson import ObjectId

app = Bottle()
plugin = MongoPlugin(uri="mongodb://127.0.0.1", db="app", json_mongo=True)
app.install(plugin)


@app.get('/')
def hello():
    return 'Hello, World!'


def save_and_trigger(data, mongodb):

    result = mongodb.requests.find_one(data, {'status': 1, "id": 1})
    print(result)
    if not result:
        data['status'] = 'queued'
        data['request_time'] = str(datetime.datetime.now())
        resp = mongodb.requests.insert_one(data)
        result = mongodb.requests.find_one({"_id": resp.inserted_id})
    return result


@app.post('/collect')
def collect(mongodb):
    print("here")
예제 #8
0
import bottle
import json
from bottle.ext.mongo import MongoPlugin
import os
from bson.json_util import dumps
import requests
import re

app = bottle.Bottle()
db_user = os.environ.get('DB_USER')
db_pass = os.environ.get('DB_PASS')
plugin = MongoPlugin(
    uri='mongodb://%s:%[email protected]:31278/seng371' %
    (db_user, db_pass),
    db="seng371",
    json_mongo=True)
app.install(plugin)


@app.get('/')
def index():
    return bottle.static_file("index.html", root="public/app/views")


@app.get('/app/views/pages/<filename:re:.*\.html>')
def pages(filename):
    return bottle.static_file(filename, root='public/app/views/pages')


@app.get('/app/views/pages/<filename:re:.*\.json>')
def json(filename):
예제 #9
0
from bottle import Bottle,redirect, response
from bottle.ext.mongo import MongoPlugin
from bson.json_util import dumps

app = Bottle()

plugin = MongoPlugin(uri="mongodb://127.0.0.1/27017", db="mydb", json_mongo=True)

@app.route('/get', method='GET')
def index(mongodb):
    return dumps(mongodb['collection'].find())

@app.route('/post/<name>/<place>') #Optional parameters<param:int>
def create(mongodb, name, place):
    mongodb['collection'].insert({'name': name, 'b': 2})
    redirect("/get")

@app.post('/post1')
def post1():

app.install(plugin) #will be applied to all routes of this application

app.run(reloader=True, port=8080)
예제 #10
0
from __future__ import unicode_literals, division

# coding=utf-8
import gevent
from gevent import monkey

monkey.patch_all()
from bson.json_util import dumps
import bottle
import pymongo
from bottle.ext.mongo import MongoPlugin

from utils import to_age

app = bottle.Bottle()
plugin = MongoPlugin(uri="mongodb://127.0.0.1", db="highload", json_mongo=True)
app.install(plugin)


@app.get('/users/<id:int>')
def get_user(id, mongodb):
    user = mongodb.users.find_one({'_id': id}, {'_id': False, 'age': False})
    if user:
        return user
    return bottle.HTTPError(404)


@app.get('/locations/<id:int>')
def get_location(id, mongodb):
    location = mongodb.locations.find_one({'_id': id}, {'_id': False})
    if location:
예제 #11
0
import json
import bottle
from bottle import Bottle, run, request, response, abort, hook, HTTPResponse
from bottle.ext.mongo import MongoPlugin
from truckpad.bottle.cors import CorsPlugin, enable_cors

from bson.json_util import dumps
from bson.objectid import ObjectId

app = Bottle()

with open("config.json") as f:
    app.config.load_dict(json.load(f))

plugin = MongoPlugin(uri="mongodb://{}".format(app.config['db.host']),
                     db=app.config['db.name'],
                     json_mongo=True)
app.install(plugin)

ENTITY_COLLECTION_MAP = {
    'channels': 'station',
    'recordings': 'recording',
    'fragments': 'fragment'
}


def raise_error(message, code=400):
    raise HTTPResponse(body=json.dumps({"message": message}),
                       status=code,
                       headers={'Content-type': 'application/json'})
예제 #12
0
from bottle.ext.mongo import MongoPlugin

database_name = 'heroku_4q7l2460'
db_uri = 'mongodb://*****:*****@ds137336.mlab.com:37336/heroku_4q7l2460'
db_plugin = MongoPlugin(uri=db_uri, db=database_name, json_mongo=True)
예제 #13
0
from bottle import Bottle
from bottle.ext.mongo import MongoPlugin

app = Bottle()
db_plugin = MongoPlugin(uri='mongodb://127.0.0.1:27017/', db='local')
app.install(db_plugin)


@app.route('/')
def index(mongodb):
    mongodb['test_collection'].insert({'key': 'value1'})
    mongodb['test_collection'].insert({'key': 'value2'})
    return 'Inserted data'


@app.route('/get')
def get_all(mongodb):
    query = mongodb['test_collection'].find()
    results = []
    for q in query:
        results.append(q['key'])
    return {'result': results}


app.run(debug=True, reLoader=True)
예제 #14
0
    return markdown2.markdown(string, extras=["fenced-code-blocks"])


def generate_post_url():
    return


# Template filter and setting
template_settings = dict(filters={
    "datetime_to_date": datetime_to_date,
    "markdown": markdown
})
template = partial(jinja2_template, template_settings=template_settings)

# Database
plugin = MongoPlugin(uri='mongodb://127.0.0.1', db='tears', json_mongo=True)
app.install(plugin)

client = pymongo.MongoClient("localhost", 27017)
db = client.tears

###############################################################################
# core #########################################################################
###############################################################################


@app.route('/static/:filename#.*#')
def serve_static(filename):
    return static_file(filename, root='./static/')

예제 #15
0
 def setUp(self):
     self.app = bottle.Bottle(catchall=False)
     plugin = MongoPlugin(uri="mongodb://0.0.0.0",
                          db="bottle", json_mongo=True)
     self.plugin = self.app.install(plugin)
예제 #16
0
def enable_cors(fn):
    def _enable_cors(*args, **kwargs):
        response.headers['Access-Control-Allow-Origin']= '*'
        response.headers['Access-Control-Allow-Methods']= 'GET,POST,PUT,OPTIONS'
        response.headers['Access-Control-Allow-Headers']= 'Origin, Accept, Content-Type,X-Requested-Width, X-CSRF-Token'

        if bottle.request.method !=  'OPTIONS':
            print("inside options")
            return fn(*args, **kwargs)
    return _enable_cors
'''

app = Bottle()
database_name = 'memo_in_api'
db_uri = 'mongodb://*****:*****@ds030719.mlab.com:30719/memo_in_api'
db_plugin = MongoPlugin(uri=db_uri, db=database_name)
app.install(db_plugin)


@app.hook('after_request')
def enable_cors_new():
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers[
        'Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
    response.headers[
        'Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type,X-Requested-Width, X-CSRF-Token'


# GET REQUESTS
#ex. GET http://127.0.0.1:8000/
''' Gets all of the data in the database collection '''
예제 #17
0
파일: stream.py 프로젝트: yenchih/mining
import gc

from bottle import Bottle, abort, request
from bottle.ext.websocket import websocket
from bottle.ext.mongo import MongoPlugin

from pandas import DataFrame

from mining.utils import conf
from mining.utils._pandas import df_generate, DataFrameSearchColumn
from mining.db.datawarehouse import DataWarehouse


stream_app = Bottle()
mongo = MongoPlugin(
    uri=conf("mongodb")["uri"],
    db=conf("mongodb")["db"],
    json_mongo=True)
stream_app.install(mongo)


@stream_app.route('/data/<slug>', apply=[websocket])
def data(ws, mongodb, slug):
    if not ws:
        abort(400, 'Expected WebSocket request.')

    DW = DataWarehouse()

    element = mongodb['element'].find_one({'slug': slug})

    element['page_limit'] = 50
    if request.GET.get('limit', True) is False:
예제 #18
0
from functions import *
from models import dengue
from prediction import *

from bottle.ext.mongo import MongoPlugin
from bottle import Bottle, route, get, post, template, redirect, static_file, error, run, request, response, default_app

data_download_template = 'static/files/templates/data_download.xlsx'

APP_TITLE = 'Epidemiología | '

debugging = True

app = Bottle()
plugin = MongoPlugin(uri=os.environ['MONGODB_URI'],
                     db="heroku_r18zcfb4",
                     json_mongo=True,
                     keyword='mongodb')


def is_auth(mongodb, cookie):
    return mongodb.sessions.count({'cookie': cookie}) > 0


def check_login(mongodb, user, password):
    userData = mongodb.users.find_one({'user': user})

    if (userData):
        if (bcrypt.checkpw(password.encode('utf8'), userData["hash"])):
            if (userData["role"] == "admin"):
                return 3
            elif (userData["role"] == "editor"):