Exemple #1
0
def main(event, context):
    q_id = event.get("pathParameters").get("id")
    (is_deleted, deletion_errors) = delete(q_id)
    if is_deleted:
        return response.no_content()
    else:
        return response.failure({"error": deletion_errors})
Exemple #2
0
def main(event, context):
    questions = collect_questions()
    if questions:
        message_dict = frame_message(questions)
        if message_dict["attachments"]:
            r = requests.post(url=SLACK_WEBHOOK_URL, json=message_dict)
            if r.text == "ok":
                log.debug("## QoTW Posted")
                for question in questions:
                    question.update_timestamp()
                log.debug("## QoTW posted on {}".format(datetime.date.today()))
                return response.success({"status": "true"})
            log.error("## QotW Error Occurred")
            return response.failure({"status": "false"})
    else:
        log.error("## QotW Error Occurred")
        return response.failure({"status": "false"})
Exemple #3
0
def update(post_data, q_id):
    query = Question.objects(question_id=q_id)
    if query:
        question = query[0]
        question.question_text = post_data.get("question_text")
        question.sample_input = post_data.get("sample_input")
        question.sample_output = post_data.get("sample_output")
        question.explanation = post_data.get("explanation")
        question.question_type = post_data.get("question_type")
        try:
            question.update_timestamp()
        except Exception as e:
            return response.failure({"status": "Failure occured.",
                                     "error": str(e)})
        log.debug("## Question Updated: ID {}".format(question.question_id))
        return response.success(question.to_dict())
    else:
        return response.failure({"error": "Question not found"})
Exemple #4
0
def handler(event, context):
    status = 200
    if status == 200:
        response = success(json.dumps(event))
    else:
        response = failure(json.dumps(event))
    print(json.dumps(response))

    return response
def create(post_data):
    question_text = post_data.get("question_text")
    sample_input = post_data.get("sample_input")
    sample_output = post_data.get("sample_output")
    explanation = post_data.get("explanation")
    question_type = post_data.get("question_type")
    q = Question(question_id=shortuuid.uuid(),
                 question_text=question_text,
                 sample_input=sample_input,
                 sample_output=sample_output,
                 explanation=explanation,
                 question_type=question_type)
    try:
        obj = q.save()
        log.debug("## Question Added: ID {}".format(obj.question_id))
        return_dict = obj.to_dict()
        return return_dict
    except Exception as e:
        log.error(e)
        return response.failure({"status": "Failure occurred."})