Ejemplo n.º 1
0
def add_response(opportunity_id, student, mobile_number, outcome):
    response = {}

    now = utils.to_timestamp(datetime.datetime.utcnow())

    response['opportunity_id'] = opportunity_id
    response['student'] = student
    response['mobile_number'] = mobile_number
    response['outcome'] = outcome
    response['time_of_response'] = int(now)

    logger.debug(response)

    result = add_record('responses', response)
    print(result)
    return result
Ejemplo n.º 2
0
def add_opportunity(op):
    print(op)
    new_op = {}

    now = utils.to_timestamp(datetime.datetime.utcnow())

    new_op['teacher'] = op['doctor']
    new_op['skill'] = op['procedure']
    new_op['expiry_time'] = int(now + int(op["duration"]) * 60)
    new_op['time_sent'] = int(now)
    new_op['location'] = op["location"]

    result = add_record('opportunities', new_op)

    new_id = result['id']
    return new_id
Ejemplo n.º 3
0
def get_all_opportunities():
    all_opportunities = get_sheet_all_records('opportunities')

    for opportunity in all_opportunities:
        if opportunity["outcome"] == "ATTENDED":
            opportunity["status"] = "Attended"
        elif opportunity["outcome"] == "NOT_ATTENDED":
            opportunity["status"] = "Not Attended"
        elif opportunity["student"]:
            opportunity["status"] = "Accepted"
        elif utils.to_timestamp(datetime.datetime.utcnow()) > int(opportunity["expiry_time"]):
            opportunity["status"] = "Expired"
        else:
            opportunity["status"] = "Offered"

        opportunity["time"] = datetime.datetime.fromtimestamp(opportunity["time_sent"])

    return all_opportunities
Ejemplo n.º 4
0
def add_sms_log(from_number, to_number, body, direction):
    try:
        now = int(utils.to_timestamp(datetime.datetime.utcnow()))

        new_sms_log = {
            'timestamp': now,
            'from': from_number,
            'to': to_number,
            'body': body,
            'direction': direction
        }

        add_record('messages', new_sms_log)

    except Exception as e:
        logger.error("Error adding SMS log", exc_info=True)

    return
Ejemplo n.º 5
0
def allocate_opportunity(opportunity_id, student_name):
    logger.debug("Attempting to update opportunity record with allocation")

    now = int(utils.to_timestamp(datetime.datetime.utcnow()))

    opportunity = get_opportunity(opportunity_id)

    if opportunity['student'] is None:
        logger.debug('No student allocated for this opportunity yet')

        patch_object = {
            'student': student_name,
            'accepted_time': now
        }

        update_record('opportunities', opportunity_id, patch_object)

        logger.debug('Record updated')

        return True

    else:
        logger.debug('Student already allocated for this opportunity')
        return False