Ejemplo n.º 1
0
def upload_product():
    name = request.json['name']
    price = request.json['price']
    description = request.json.get('description', None)
    image = request.json.get('image', None)

    Products.addProduct(name, price, description, image)

    response_object = {
        'status': 'success',
        'message': 'item inserted into database'
    }
    return jsonify(response_object), 201
Ejemplo n.º 2
0
def get_product(id):
    try:
        product = Products.get(id)
        if not product:
            response_object = {
                'status': 'failure',
                'message': 'Invalid product id'
            }
            return jsonify(response_object), 400

        response_object = {
            'status': 'success',
            'product': {
                'id': product.id,
                'name': product.name,
                'price': product.price,
                'description': product.description,
                'image': product.image
            }
        }
        return jsonify(response_object), 200
    except:
        response_object = {
            'status': 'failure',
            'message': 'Server issue encoutered'
        }
        return jsonify(response_object), 500
Ejemplo n.º 3
0
def get_products():
    try:
        response_object = {
            'status': 'success',
            'products': []
        }

        products = Products.getAll()

        if not products:
            response_object = {
                'status': 'success',
                'message': 'No content available'
            }
            return jsonify(response_object), 204

        for item in products:
            response_object['products'].append({
                'id': item.id,
                'name': item.name,
                'price': item.price,
                'description': item.description,
                'image': item.image
            })

        return jsonify(response_object), 200
    except:
        response_object = {
            'status': 'failure',
            'message': 'server error encountered'
        }
        return jsonify(response_object), 500
Ejemplo n.º 4
0
def get_orders():
    orders_dict = {
        'status': 'success',
        'orders': [],
    }
    orders = Orders.getAll()

    if not orders:
        response_object = {
            'status': 'success',
            'message': 'No content available'
        }
        return jsonify(response_object), 204

    for order in orders:

        single_order_dict = {
            'id': order.id,
            'products': [],
            'cost': 0.0,
            'customer': Customers.get_shipment_info(order.customer_id),
            'dateCreated': order.datetimecreated,
            'status': order.getStatus(),
            'tracking code': order.tracking_website
        }

        for id in Orders.getProducts(order.id):
            item = OrderDetails.get(id)
            single_order_dict[
                'cost'] = item.item_cost * item.quantity + single_order_dict[
                    'cost']
            product = Products.get(item.product_id)

            item_dict = {
                'product': product.name if product else 'DELETED PRODUCT',
                'quantity': item.quantity,
                'price': item.item_cost
            }

            single_order_dict['products'].append(item_dict)

        orders_dict['orders'].append(single_order_dict)

    return jsonify(orders_dict), 200
Ejemplo n.º 5
0
def update_product(id):
    if request.method == 'PUT':
        name = request.json.get('name', None)
        price = request.json.get('price', None)
        description = request.json.get('description', None)
        image = request.json.get('image', None)

        if (not name and not price and not description and not image):
            response_object = {'status': 'failure', 'message': 'Empty request'}
            return jsonify(response_object), 400

        if not Products.isValidProduct(id):
            response_object = {
                'status': 'failure',
                'message': 'invalid product id'
            }
            return jsonify(response_object), 400

        Products.updateProduct(id, name, price, description, image)

        response_object = {
            'status': 'success',
            'message': 'item was updated in table'
        }
        return jsonify(response_object), 200
    if request.method == 'DELETE':

        if not Products.isValidProduct(id):
            response_object = {
                'status': 'failure',
                'message': 'Item not in table'
            }
            return jsonify(response_object), 400

        Products.deleteProduct(id)

        response_object = {
            'status': 'success',
            'message': 'item was deleted from table'
        }
        return jsonify(response_object), 200
Ejemplo n.º 6
0
def purchase_products():
    data = request.get_json()
    returning_customer = data.get('returningCustomer')
    email = data.get('email')
    products_selected = data.get('items')
    password = data.get('password')
    first_name = data.get('firstName')
    last_name = data.get('lastName')
    address = data.get('address')
    appartment = data.get('appartment')
    city = data.get('city')
    state = data.get('state')
    country = data.get('country')
    zip_code = data.get('zipCode')
    phone_number = data.get('phoneNumber')

    # Validate products selected
    if products_selected is None:
        return jsonify({
            'status': 'failure',
            'message': 'no products found'
        }), 400
    else:
        for item in products_selected:
            if not Products.get(item['id']):
                return jsonify({
                    'status': 'failure',
                    'message': 'one or more invalid products'
                }), 400

    customer_id = None
    if returning_customer:
        if email is None or password is None:
            return jsonify({
                'status': 'failure',
                'message': 'Missing email or password'
            }), 400

        customer_id = Customers.get_customer_id(email, password)
    else:
        if (first_name is None or last_name is None or email is None
                or address is None or city is None or country is None
                or zip_code is None or phone_number is None):
            return jsonify({
                'status': 'failure',
                'message': 'Missing important information'
            }), 400

        customer_id = Customers.add(first_name, last_name, email, password,
                                    address, appartment, city, country, state,
                                    zip_code, phone_number)

    product_orders = []
    for item in products_selected:
        if item['quantity'] > 0:
            product = Products.get(item['id'])
            order_id = OrderDetails.new(product.id, item['quantity'],
                                        product.price)
            product_orders.append(order_id)

    if customer_id is not None and product_orders is not None:
        Orders.new(customer_id, product_orders)
    else:
        return jsonify({'status': 'failure'}), 500

    return jsonify({'status': 'success'}), 200
Ejemplo n.º 7
0
def searchProduct():
    product_name = st.text_input('enter the product name to show')
    amz_urls = st.text_input('Enter url for amazon')
    flip_urls = st.text_input('Enter url for flipkart')
    myn_urls = st.text_input('Enter url for Myntra')
    btn = st.button('Check tracker')
    if (amz_urls or flip_urls or myn_urls) and btn:
        df = []
        if amz_urls:
            details = sc.extract_amazon_data(amz_urls)
            df.append(details)

        if flip_urls:
            details = sc.extract_flipkart_data(flip_urls)
            df.append(details)

        if myn_urls:
            details = sc.extract_myntra_data(myn_urls)
            df.append(details)

        st.write(df)

        st.markdown(f"""
            <h2>Name : </h2>
            <h3>{df[0]['name']}</h3>
            <h2>Name : </h2>
            <h3>{df[0]}</h3>
        """,
                    unsafe_allow_html=True)

    st.subheader('Run Tracker ')
    time_gap = st.select_slider(
        "How Much time difference between each tracking call", [
            'No delay', '10 sec', '10 mins', '1 hour', '12 hours', '1 day',
            '3 days'
        ])
    mail_addr = st.text_input("Enter Your Mail")
    btn2 = st.button('Run Tracker continously')

    if (amz_urls or flip_urls or myn_urls) and btn2 and mail_addr:
        if time_gap == '10 sec':
            wait = 10
        elif time_gap == '10 mins':
            wait = 60 * 10
        elif time_gap == '1 hour':
            wait = 60 * 60
        elif time_gap == '12 hours':
            wait = 60 * 60 * 12
        elif time_gap == '1 day':
            wait = 60 * 60 * 24
        elif time_gap == '3 day':
            wait = 60 * 60 * 24 * 3
        elif time_gap == 'No delay':
            wait = 0
        else:
            wait = 5

        dfs = []
        while True:
            if amz_urls:
                details = sc.extract_amazon_data(amz_urls)
                details['date'] = datetime.utcnow()
                product = Products(name=details['name'],
                                   price=details['price'],
                                   deal=details['deal'],
                                   url=details['url'],
                                   date=details['date'],
                                   website=details['website'])
                dfs.append(details)
                sess.add(product)
                sess.commit()
            if flip_urls:
                details = sc.extract_flipkart_data(flip_urls)
                details['date'] = datetime.utcnow()
                product = Products(name=details['name'],
                                   price=details['price'],
                                   deal=details['deal'],
                                   url=details['url'],
                                   date=details['date'],
                                   website=details['website'])
                dfs.append(details)
                sess.add(product)
                sess.commit()
            if myn_urls:
                details = sc.extract_myntra_data(myn_urls)
                details['date'] = datetime.utcnow()
                product = Products(name=details['name'],
                                   price=details['price'],
                                   deal=details['deal'],
                                   url=details['url'],
                                   date=details['date'],
                                   website=details['website'])
                dfs.append(details)
                sess.add(product)
                sess.commit()

            data = pd.DataFrame(dfs)
            data['date'] = pd.to_datetime(data['date'])
            fig = px.line(data_frame=data,
                          x=data.index,
                          y=data['price'],
                          line_group='name',
                          color='website')
            plot_area.subheader('graphical output')
            plot_area.plotly_chart(fig)
            data_area.write(data)
            if mail_addr and data.shape[0] >= 12:
                lowest_value = 0
                amzdata = data[data.website == 'amazon']
                flipkartdata = data[data.website == 'flipkart']
                myntradata = data[data.website == 'myntra']
                if amz_urls:
                    if amzdata.iloc[-1]['price'] < amzdata.iloc[-2]['price']:
                        if sendMail(mail_addr, amz_urls, product_name,
                                    amzdata.iloc[-1]['price'],
                                    amzdata.iloc[-1]['website']):
                            st.success(
                                'Price fell at amazon , mail notification sent to {mail_addr}'
                            )
                if flip_urls:
                    if flipkartdata.iloc[-1]['price'] < flipkartdata.iloc[-2][
                            'price']:
                        if sendMail(mail_addr, flip_urls, product_name,
                                    flipkartdata.iloc[-1]['price'],
                                    flipkartdata.iloc[-1]['website']):
                            st.success(
                                'Price fell at flipkart , mail notification sent to {mail_addr}'
                            )

                if myn_urls:
                    if myntradata.iloc[-1]['price'] < myntradata.iloc[-2][
                            'price']:
                        if sendMail(mail_addr, myn_urls, product_name,
                                    myntradata.iloc[-1]['price'],
                                    myntradata.iloc[-1]['website']):
                            st.success(
                                'Price fell at myntra , mail notification sent to {mail_addr}'
                            )

            time.sleep(wait)

    op = st.sidebar.checkbox("show tracked product data manually")
    if op:
        try:
            df = pd.read_sql('products', engine)
            st.write(df)
        except Exception as e:
            st.error('No tracking data available')
Ejemplo n.º 8
0
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, Column, String, Integer, Float
import pandas as pd
from database import Products

# connect to database
engine = create_engine('sqlite:///db.sqlite3')
Session = sessionmaker(bind=engine)
sess = Session()

# data base code ends

st.title("Welcome to Product inventory adder")
name = st.text_input('product name')
price = st.number_input('product price')
brand = st.text_input('product brand')

if st.button("save") and name and price and brand:
    with st.spinner("saving..."):
        product = Products(name=name, price=price, brand=brand)
        sess.add(product)
        sess.commit()
        st.success("saved to database")
else:
    st.error("error")

op = st.checkbox("show products from database")
if op:
    df = pd.read_sql('products', engine)
    st.write(df)