Ejemplo n.º 1
0
 def create_pita(pita):
     """
     Takes a Pita object and inserts it into the database. It will
     also update tables related to Pita events.
     """
     cur = get_db().cursor()
     q = (
         "INSERT INTO pitas (aid, state, parent_a, parent_b, name, body_hue, "
         + "spots_hue, tail_hue, has_spots) "
         + "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING pid"
     )
     cur.execute(
         q,
         [
             pita.aid,
             pita.state,
             pita.parent_a,
             pita.parent_b,
             pita.name,
             pita.body_hue,
             pita.spots_hue,
             pita.tail_hue,
             pita.has_spots,
         ],
     )
     pita.pid = cur.fetchone()[0]
     cur.close()
     PitaEvent.record_event(pita, "conception")
Ejemplo n.º 2
0
def record_pita_hatch():
    """
    Endpoint used to record that a user has hatched their Pita.
    """
    if not g.authorized:
        return access_denied()

    pita = Pita.get_by_account(g.account.aid)

    if not pita:
        return api_error('That account doesn\'t have a pita.')
    if pita.state != 'egg':
        return api_error('The pita is not in egg form.')

    pita.set_state('alive')
    PitaEvent.record_event(pita, 'born')

    return jsonify(status='ok')
Ejemplo n.º 3
0
def record_pita_disown():
    """
    Endpoint used to record that a Pita has been disowned.
    """
    if not g.authorized:
        return access_denied()

    pita = Pita.get_by_account(g.account.aid)

    if not pita:
        return api_error('That account doesn\'t have a pita.')

    if pita.state != 'alive' and pita.state != 'egg':
        return api_error('The pita is not alive.')

    pita.set_state('disowned')
    PitaEvent.record_event(pita, 'disowned')

    return jsonify(status='ok')