Exemplo n.º 1
0
def pairs_per_brand():
    conn = data_hooks.db_connect()
    pairs_per_brand = data_api.generate_pairs_per_brand_df(conn)
    response = Response(pairs_per_brand.to_csv(index=False))
    response.headers['Content-Type'] = 'text/csv'
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
Exemplo n.º 2
0
def add_manufacturer():
    form = ManufacturerAddForm()
    if form.validate_on_submit():
        conn = data_hooks.db_connect()
        inserted_id = data_hooks.manufacturer_insert(
            conn, form.manufacturer_name.data, form.collaborator_name.data)
        flash(inserted_id)
        conn.close()
        return redirect(url_for('index'))
    return render_template('manufacturer_add.html',
                           title='Event logged',
                           form=form)
Exemplo n.º 3
0
def log_sneaker_event():
    form = SneakerEventForm()
    if form.validate_on_submit():
        conn = data_hooks.db_connect()
        event = data_hooks.sneaker_event_insert(
            conn,
            form.sneaker_id.data,
            form.event_type.data,
            config=data_hooks.readConfigs())
        flash(event)
        conn.close()
        return redirect(url_for('index'))
    return render_template('sneaker_event.html',
                           title='Event logged',
                           form=form)
Exemplo n.º 4
0
def add_sneakers():
    form = SneakerAddForm()
    if form.validate_on_submit():
        conn = data_hooks.db_connect()
        inserted_id = data_hooks.sneaker_insert(conn, form.sneaker_name.data,
                                                form.color.data,
                                                form.purchase_price.data,
                                                form.manufacturer_id.data)
        if inserted_id:
            event = data_hooks.sneaker_event_insert(conn,
                                                    inserted_id,
                                                    'add',
                                                    config=None)
        flash('Inserted ID: ' + str(inserted_id))
        conn.close()
        return redirect(url_for('index'))
    return render_template('sneaker_add.html', title='Event logged', form=form)
Exemplo n.º 5
0
def sms_reply():
    """Respond to incoming calls with a simple text message."""
    user_term = request.values.get('Body', None)
    resp = MessagingResponse()
    conn = data_hooks.db_connect()

    if user_term.isnumeric() == False:
        #List sneakers if user sends a string
        sneakers_dict = dict(
            data_hooks.available_sneakers_search(conn, user_term.lower()))
        formatted_sneakers_list = '\n'.join([
            '%s - %s' % (key, value)
            for (key, value) in sorted(sneakers_dict.items())
        ])

        if len(formatted_sneakers_list) > 0:
            resp.message(
                "Which pair exactly?\n\n {}\n\nEnter another search term to try again."
                .format(formatted_sneakers_list))
        else:
            resp.message(
                "That search didn't return any results. Try again. Or don't, life is meaningless."
            )

    else:
        #Update database if user sends a sneaker ID
        #validate given sneaker ID is in the database
        available_ids = data_hooks.list_available_sneaker_ids(conn)
        if int(user_term) in available_ids:
            data_hooks.sneaker_event_insert(conn=conn,
                                            sneaker_id=user_term,
                                            event_type='wear',
                                            event_time=datetime.utcnow(),
                                            config=None)
            resp.message(
                "Wear recorded for sneaker_id {}. Wear them while you still can."
                .format(user_term))
        else:
            resp.message(
                "That sneaker_id doesn't exist in the SNQL database or isn't owned (yet). Try searching again or entering a sneaker_id directly. Or don't, life is meaningless."
            )

    return str(resp)
Exemplo n.º 6
0
def remove_sneakers():
    form = SneakerTrashOrGiveForm()
    if form.validate_on_submit():
        conn = data_hooks.db_connect()
        event = data_hooks.sneaker_event_insert(
            conn=conn,
            sneaker_id=form.sneaker_to_remove.data,
            event_type=form.remove_type.data,
            event_time=form.remove_date.data or datetime.utcnow(),
            config=None)
        remove_update = data_hooks.sneaker_remove(
            conn=conn,
            sneaker_id=form.sneaker_to_remove.data,
            remove_type=form.remove_type.data,
            event_time=form.remove_date.data or datetime.utcnow())
        flash(event, remove_update)
        conn.close()
        return redirect(url_for('index'))
    return render_template('sneaker_remove.html',
                           title='Event logged',
                           form=form)
Exemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.sneaker_to_remove.choices = data_hooks.list_available_sneakers(data_hooks.db_connect())
Exemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.manufacturer_id.choices = data_hooks.list_available_manufacturers(data_hooks.db_connect())