示例#1
0
def filter(cat, db):
    """Render the category page"""
    session.get_or_create_session(db)
    product = {}
    temp = model.product_list(db, cat)
    cat_count = len(temp)
    if cat_count is not 0:
        # for i in range(cat_count):
        #     product[i] = []
        for i in range(cat_count):
            product[i] = [temp[i]]
        if product is not None:
            info = {
                'title': 'The WT',
                'products': product,
                'number': cat_count,
            }
            return template('index', info)
        else:
            info = {
                'title': "No products in this category",
                'products': product,
                'number': cat_count,
            }
            return template('index', info)
def index(db):
    session.get_or_create_session(db)
    productid = request.forms.get("product")
    quantity = request.forms.get("quantity")
    session.add_to_cart(db, productid, quantity)
    session.get_or_create_session(db)
    redirect('/cart')
示例#3
0
def cart(db):
    session.get_or_create_session(db)

    info = {
        'contents': session.get_cart_contents(db),
    }
    return template('cart', info)
示例#4
0
def post_cart_page(db):
    session.get_or_create_session(db)
    new_product = request.forms.get("product")
    new_quantity = request.forms.get("quantity")
    session.add_to_cart(db, new_product, new_quantity)
    session.get_or_create_session(db)
    redirect('/cart')
示例#5
0
文件: main.py 项目: natlec/WT
def cart(db):

    # Get or set session cookie
    session.get_or_create_session(db)

    # Get cart contents from database
    cart = session.get_cart_contents(db)

    # Info relative to page
    info = {
        'page': 'cart',
        'title': 'Shopping cart',
        'description':
        "You've added the following items to your shopping cart:",
        'cart': 0,
        'total': 0
    }

    # Get item list for cart
    info['products'] = cart

    # Get cart items count & total cost
    if cart:
        for item in cart:
            info['cart'] += int(item['quantity'])
            info['total'] += (float(item['cost']) * float(item['quantity']))

    return template('cart', info)
示例#6
0
def about(db):
    """Generates the about page"""
    session.get_or_create_session(db)
    info = {
        'title': "Welcome to WT! The innovative online store"
    }
    return template('about', info)
示例#7
0
def index(db):
    session.get_or_create_session(db)
    products = model.product_list(db)

    info = {'title': "The WT Store", "products": products}

    return template('index', info)
示例#8
0
文件: main.py 项目: natlec/WT
def products(db, category):

    # Get or set session cookie
    session.get_or_create_session(db)

    # Get cart contents from database
    cart = session.get_cart_contents(db)

    # Check if category exists
    if category == 'men' or category == 'women':

        # Info relative to page
        info = {
            'page': category,
            'title': "%s's products" % category,
            'description':
            "Explore our entire range of %s's products." % category,
            'cart': 0
        }

        # Get cart items count
        if cart:
            for item in cart:
                info['cart'] += int(item['quantity'])

        # Get products list
        info['products'] = model.product_list(db, category)

        return template('index', info)
    else:
        return HTTPResponse(status=404)
示例#9
0
文件: main.py 项目: natlec/WT
def index(db):

    # Get or set session cookie
    session.get_or_create_session(db)

    # Get cart contents from database
    cart = session.get_cart_contents(db)

    # Info relative to page
    info = {
        'page': '',
        'title': 'All products',
        'description':
        'Explore our entire range of products for both men & women. ',
        'cart': 0
    }

    # Get cart items count
    if cart:
        for item in cart:
            info['cart'] += int(item['quantity'])

    # Get products list
    info['products'] = model.product_list(db)

    return template('index', info)
示例#10
0
def productpage(db, id):
    session.get_or_create_session(db)
    info = {
        'product': model.product_get(db, id),
    }

    return template('product', info)
示例#11
0
def about(db):
    """Generates the about page"""
    session.get_or_create_session(db)
    about_content = dict()
    about_content['title'] = "Welcome to WT! The innovative online store"
    about_content['description'] = "Designed by Roy"
    return template('about', about_content)
示例#12
0
def about(db):
    session.get_or_create_session(db)
    info = {
        'title': "The WT Store",
        "body": "Welcome to WT! The innovative online store"
    }

    return template('about', info)
示例#13
0
def product(db, id):
    session.get_or_create_session(db)
    product = model.product_get(db, id=id)
    if product is None:
        return HTTPError(status=404, body="404 Not Found")
    info = {'product': product}
    session.response.set_cookie('new_cookie', 'dummy', path="/")
    return template('products', info)
示例#14
0
def get_index_page(db):
    session.get_or_create_session(db)
    data = model.product_list(db)
    info = {
        'title': "The WT Store",
        'message': data,
    }

    return template('index', info)
示例#15
0
文件: main.py 项目: natlec/WT
def emptyCart(db):

    # Get or set session cookie
    session.get_or_create_session(db)

    # Add item to cart
    session.empty_cart(db)

    # Redirect to cart page
    return redirect('cart')
示例#16
0
def category(db, cat):
    session.get_or_create_session(db)
    if cat == "men" or cat == "women":
        products = model.product_list(db, category=cat)
    else:
        products = "No products in this category"

    info = {'products': products}

    return template('category', info)
示例#17
0
文件: main.py 项目: natlec/WT
def addToCart(db):

    # Get or set session cookie
    session.get_or_create_session(db)

    # Add item to cart
    session.add_to_cart(db, request.forms.get('product'),
                        request.forms.get('quantity'))

    # Redirect to cart page
    return redirect('cart')
示例#18
0
def get_about_page(db):
    session.get_or_create_session(db)
    info = {
        'title':
        "The WT Store",
        'message':
        "Welcome to WT! The innovative online store. You will find beautifully designed and artistically crafted items"
        "for all your needs.",
    }

    return template('about', info)
示例#19
0
def index(db):
    """The home page. Will create/get cookie.
    Returns the index file with the title and
    the list of all products in the store.
    Index will iterate over the list and display
    each product.
    """
    session.get_or_create_session(db)

    info = {'title': "The WT Store", 'products': model.product_list(db)}
    return template('index', info)
示例#20
0
def index(db):
    """Render the index page"""
    session.get_or_create_session(db)
    products = model.product_list(db)
    count = len(products)
    info = {
        'title': 'The WT',
        'products': products,
        'number': count,
    }
    return template('index', info)
示例#21
0
def index(db):
    session.get_or_create_session(db)
    data = model.product_list(db)
    info = {
        'title': ' The WT Store',
        'data': data,
    }
    return template(
        'index',
        info,
    )
示例#22
0
def cart(db):
    session.get_or_create_session(db)
    cart = session.get_cart_contents(db)
    total_cost = 0
    if len(cart) is 0:
        cart = "Your Cart is Empty"
    else:
        for item in cart:
            total_cost = total_cost + item["cost"]
    info = {"title": "CART", "cart": cart, "total_cost": total_cost}

    return template('cart', info)
示例#23
0
def product_page(db, id):
    """Render the product page"""
    session.get_or_create_session(db)
    prod = model.product_get(db, id)
    if prod is None:
        abort(404)
    else:
        info = {
            'products': prod,
            'number': 1,
        }
        return template('product', info)
示例#24
0
def cart_view(db):
    """Render the cart(GET) page"""
    session.get_or_create_session(db)
    current = session.get_cart_contents(db)
    cost = 0
    for each in current:
        cost += each['cost'] * each['quantity']
    cart = {
        'content': current,
        'total': cost,
    }
    return template('cart', cart)
示例#25
0
def show_cart(db):
    """a GET request to this URL shows the current contents of the shopping cart. The resulting page
includes a listing of all items in the cart, including their name, quantity and overall cost. It also
includes the total cost of the items in the cart."""
    # product_id = request.query.get('item')
    # product_quantity = request.query.get('quantity')
    # add_to_cart(product_id, product_quantity)
    session.get_or_create_session(db)
    cart = dict()
    cart['title'] = "Your Cart: "
    cart['product_list'] = session.get_cart_contents(db)
    return template('cart', cart)
示例#26
0
def cart_view(db):
    """Render the cart(GET) page"""
    session.get_or_create_session(db)
    cart = session.get_cart_contents(db)
    totalCost = 0
    for item in cart:
        totalCost += item['cost'] * item['quantity']
    cart = {
        'products': cart,
        'total': totalCost
    }
    return template('cart', cart)
示例#27
0
def product_page(db, id):
    """Render the product page"""
    session.get_or_create_session(db)
    product = model.product_get(db, id)
    if product is not None:
        info = {
            'products': product,
            'number': 1,
        }
        return template('product', info)
    else:
        return HTTPError(status=404, body="404 Not Found")
示例#28
0
def index(db):
    session.get_or_create_session(db)
    data = session.get_cart_contents(db)
    cost = 0
    for x in data:
        temp = x['cost']
        cost += temp
    info = {
        'title': 'Current Shopping Cart Contents',
        'data': data,
        'cost': cost
    }
    return template('cart', info)
示例#29
0
def cart(db):
    """with variables `product` (the product id, an integer) and `quantity` (an integer) adds a new entry to the
shopping cart.  The response to the POST request is a **redirect to the cart page `/cart`**. When
the browser gets this redirect response it will make a new GET request to `/cart` and the
resulting page will contain the updated shopping cart contents."""
    session.get_or_create_session(db)
    product_id = request.forms.get('product')
    product_quantity = request.forms.get('quantity')
    if int(product_quantity) < 0:
        product_quantity = 0
    # add_to_cart(product_id, product_quantity)
    session.add_to_cart(db, product_id, product_quantity)
    # return show_cart(db)
    return redirect("/cart")
示例#30
0
def category(db, cat):
    """Generates the category page, where products are shown according to the category (male, female) requests"""
    if cat is not None:
        session.get_or_create_session(db)
        products = dict()
        products['product_list'] = model.product_list(db, cat)
        if len(products['product_list']) == 0:
            products['title'] = "No products in this category"
        else:
            products['title'] = "Category: " + cat.capitalize()
        # print(products['product_list'])
        return template('index', products)
    else:
        return HTTPError(404, "There is no content to show!")
示例#31
0
    def __init__(self):
        self.db = db_client
        self.session = get_or_create_session()

        # Seed user and necessary index
        insert_new_user(self.db, user_id=Magic.seed_user)

        self.db.answers.ensure_index("answer_id")
        self.db.answers.ensure_index("author")
        self.db.answers.ensure_index("relate_question")
        self.db.questions.ensure_index("question_id")
        self.db.questions.ensure_index("touched")
        self.db.users.ensure_index("touched")
        self.db.users.ensure_index("user_id")
示例#32
0
from db import insert_new_question, insert_new_user, insert_answer, \
    get_user_cursor, get_untouched_question_cursor, FLAG
from db import db_client, change_user_status, change_question_status
from constants import Magic, BS_PARSER
from logger import log
from session import get_or_create_session
from settings import EXPLORE_USER_COUNT, EXPLORE_QUESTION_COUNT, CONCURRENCY

import asyncio
import re

from bs4 import BeautifulSoup


loop = asyncio.get_event_loop()
session = loop.run_until_complete(get_or_create_session())
sem = asyncio.Semaphore(CONCURRENCY)


async def get_page_body(url: str) -> str:
    await sem.acquire()
    rsp = await session.get(url)
    data = await rsp.read()
    content = data.decode('utf-8')
    rsp.close()
    sem.release()
    return content


class Crawler: