예제 #1
0
def claimPot():
    """Lets a user claim to have made a teapot

    Args:
        - None
    Returns:
        - {'submitMessage': 'Error / Success Message'}
    """
    latest_full_pot = State.get_latest_full_teapot()
    if latest_full_pot.claimed_by:
        return jsonify({'submitMessage': 'Pot has already been claimed'})
    try:
        maker = json.loads(request.data)['potMaker']
    except KeyError:
        return jsonify({'submitMessage': 'You need to select a pot maker'})

    maker = PotMaker.get_single_pot_maker(maker)
    maker.number_of_pots_made += 1
    maker.total_weight_made += latest_full_pot.weight
    maker.number_of_cups_made += latest_full_pot.num_of_cups
    if maker.largest_single_pot < latest_full_pot.weight:
        maker.largest_single_pot = latest_full_pot.weight
    maker.save()
    latest_full_pot.claimed_by = maker
    latest_full_pot.save()
    return jsonify({'submitMessage': 'Pot claimed, thanks, %s' % maker.name})
예제 #2
0
def teapotAge():
    """Returns a JSON blob containing the age of the teapot in minutes

    Args:
        - None
    Returns
        - {teapotAge: X}
    """
    latest_pot = State.get_latest_full_teapot()
    teapot_age = _get_current_time() - latest_pot.timestamp
    teapot_age = teapot_age.total_seconds() / 60

    return jsonify({"teapotAge": teapot_age})
예제 #3
0
def teaReady():
    """POST'ing to this endpoint triggers a message to be sent to Slack
    alerting everyone that a teapot is ready with X number of cups in it.

    Args:
        - num_of_cups (int) - The number of cups in the teapot
    Returns
        - 200
    """
    latest_state = State.get_newest_state()
    last_full_pot = State.get_latest_full_teapot()
    number_of_cups = latest_state.num_of_cups
    message = "The Teapot :teapot: is ready with %s" % (
        _cup_puraliser(number_of_cups))
    reaction_message = \
        "Want a cup of tea from the next teapot ? " + \
        "React to this message to let everyone know!"
    if last_full_pot.claimed_by:
        message += ", thanks to %s" % last_full_pot.claimed_by.name
    slack_communicator_wrapper.post_message_to_room(message)
    PotMaker.reset_teapot_requests()
    SlackMessages.clear_slack_message()
    slack_communicator_wrapper.post_message_to_room(reaction_message, True)
    return Response()