Esempio n. 1
0
def set_action_buoy(buoy_id, action, ignore_now=False):
    """Sets the following action of a buoy"""
    buoy_id = str(buoy_id)
    red.hset(_KEY_BUOYACTION.format(buoy_id), _ATTR_BUOYACTION_ACTION, action)
    if ignore_now:
        red.hset(_KEY_BUOYACTION.format(buoy_id), _ATTR_BUOYACTION_TIME, '')
    else:
        now = datetime.datetime.now()
        red.hset(_KEY_BUOYACTION.format(buoy_id), _ATTR_BUOYACTION_TIME,
                 now.strftime(const.STRTIME_KEY_GENERATED))
Esempio n. 2
0
def change_status(key_id, status):
    """Changes the status of a key."""
    red.hset(_KEY_APIK.format(str(key_id)), _ATTR_APIK_STATUS, status)
Esempio n. 3
0
def set_last_host_scan(key_id, last_host, last_scan):
    """Sets the last host's ip address and scan datetime."""
    red.hset(_KEY_APIK.format(str(key_id)), _ATTR_APIK_LASTHOST, last_host)
    red.hset(_KEY_APIK.format(str(key_id)), _ATTR_APIK_LASTSCAND, last_scan)
Esempio n. 4
0
def addTask():
    if not request.json:
        abort(400)

    if request.headers['Content-Type'] != 'application/json; charset=UTF-8':
        abort(400)

    username = request.json.get('username')

    if username not in session:
        return redirect('/')

    task_desc = request.json.get('description')
    task_title = request.json.get('title')
    # then update userInfo
    task_category = request.json.get('category')
    task_urgency = request.json.get('urgency') # checkbox
    due_date = request.json.get('due_date')
    locationData = request.json.get('locationData')
    contactPersons = request.json.get('contactPersons')
    task_price = request.json.get('taskPrice')
    task_creation_date = str(datetime.now())

    # unpaid status - pending - started - finished
    taskData = { "username": username, "task_title": task_title, 
    "task_desc": task_desc, "locationData": locationData, "task_category": task_category, 
    "task_urgency": "UNPAID", "due_date": due_date, "contactPersons": contactPersons, 'task_creation_date': task_creation_date }

    text_all = "taskwetu new task %s " %(task_title)

    try:
        r.table('Tasks').insert(taskData).run(g.rdb_conn)
    except RqlError:
        logging.warning('DB code verify failed on /api/addTask/')

        resp = make_response(jsonify({"Error": "503 DB error"}), 503)
        resp.headers['Content-Type'] = "application/json"
        resp.cache_control.no_cache = True
        return resp

    # send email and SMS notification
    # rabbitMQ tasks
    try:
        send_notification_task("+254710650613", str(text_all))
        new_task_message("*****@*****.**", str(taskData), username)
        new_task_message("*****@*****.**", str(taskData), username)
    except Exception:
        logging.warning('Send SMS failed on /api/addTask/ notification failed')

    try:
        user_info = r.table('UsersInfo').get(username).pluck('email').run(g.rdb_conn)
        usermobileNo = r.table('UsersInfo').get(username).pluck('mobileNo').run(g.rdb_conn)
        email = user_info['email']
        mobileNo = ""
        if usermobileNo is not None:
            mobileNo = usermobileNo['mobileNo']

    except Exception:
        logging.warning('Fetch of userInfo failed on /api/addTask/')

    # setup URL to payments - user specific data
    merchant_ref = "Ta" + str(randint(10000, 99999)) + "W"
    #merchant_ref = '12erwe'
    # amount ?
    task_price = 500
    request_data = {
        'Amount': str(task_price),
        'Description': str(task_title),
        'Type': 'MERCHANT',
        'Reference': str(merchant_ref),
        'PhoneNumber': str(mobileNo),
        'Email': str(email)
    }

    url = process_payments.postOrder(request_data)

    # store URL in redis under username
    # set with expire
    red.hset(username, 'url', url)
    red.expire(username, 300)

    # resp = make_response(redirect(pay_url, code=302))

    resp = make_response(jsonify({"OK": "Task Created"}), 200)
    resp.headers['Content-Type'] = "application/json"
    resp.cache_control.no_cache = True
    return resp