Ejemplo n.º 1
0
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.  See the License for the specific language governing
# permissions and limitations under the License.
"""

from flask import jsonify, request

from models import DB
from controllers import bad_request_response, app

database = DB()
"""
    Adds a new beacon
"""


@app.route("/api/beacon", methods=["POST"])
def add_beacon():
    data = request.get_json()
    if data.get("beacon_uuid", None) is not None:
        response = database.new_beacon(data)
    if not response:
        return bad_request_response(message="Failed! Beacon was not added")
    return jsonify({"code": 200, "message": "Success", "data": response})

Ejemplo n.º 2
0
def network_home(project_name, network, task_id=None):
    """
    Renders a project account's homepage
    """
    # Loads project details if an admin
    if g.admin is not None:
        _aload_project(project_name)

    # Grabs collectors for the given network
    if not g.project['collectors']:
        collectors = None
    else:
        collectors = [
            c for c in g.project['collectors'] if c['network'] == network
        ]
        for collector in collectors:
            collector['num_terms'] = 0

            if collector['terms_list'] is not None:
                collector['num_terms'] = len(collector['terms_list'])

        g.project['num_collectors'] = len(collectors)

    processor_form = ProcessControlForm(request.form)
    inserter_form = ProcessControlForm(request.form)

    # Loads processor active status
    db = DB()
    resp = db.check_process_status(g.project['project_id'],
                                   'process',
                                   module=network)
    processor_active_status = resp['message']

    # Loads inserter active status
    resp = db.check_process_status(g.project['project_id'],
                                   'insert',
                                   module=network)
    inserter_active_status = resp['message']

    # Loads count of tweets in the storage DB
    count = db.get_storage_counts(g.project['project_id'], network)

    # If a start/stop/restart is in progress, display the status
    task_status = None
    if task_id:
        resp = celery.AsyncResult(task_id)
        if resp.state == 'PENDING':
            processor_task_status = 'Processor/Inserter start/shutdown still in progress...'
        else:
            processor_task_status = 'Processor/Inserter start/shutdown completed.'

    return render_template('network_home.html',
                           network=network,
                           collectors=collectors,
                           project_detail=g.project,
                           processor_active_status=processor_active_status,
                           inserter_active_status=inserter_active_status,
                           task_status=task_status,
                           count=count,
                           processor_form=processor_form,
                           inserter_form=inserter_form)
Ejemplo n.º 3
0
def work():
    db = DB('main', 'work')
    resp = db.get_work_list()
    if resp['status']:
        work_list = [item for item in resp['data']]
    return render_template("work.html", work_list=work_list)