Пример #1
0
def product_refresh(request, code):
    try:
        product = Product.objects.get(code=code)
        crawler = Bloodhound()
        crawler.howl(product)
        return redirect(r('product', args=(code,)))
    except Product.DoesNotExist:
        messages.error(request, u'Product with code {0} was not found.'.format(code))
        return redirect(r('home'))
Пример #2
0
class Howl(threading.Thread):
    def __init__(self):
        super(Howl, self).__init__()
        self.crawler = Bloodhound()

    def run(self):
        while True:
            products = Product.objects.all().order_by('visited_at')
            for product in products:
                self.crawler.howl(product)
Пример #3
0
class Howl(threading.Thread):

    def __init__(self):
        super(Howl, self).__init__()
        self.crawler = Bloodhound()

    def run(self):
        while True:
            products = Product.objects.all().order_by('visited_at')
            for product in products:
                self.crawler.howl(product)
Пример #4
0
def product_details(request, code):
    try:
        product = Product.objects.get(code=code)
    except Product.DoesNotExist:
        crawler = Bloodhound()
        product = Product(code=code)
        product = crawler.howl(product)

    if product.status == Product.OK:
        price_history_chart = product.price_history.all().order_by('created_at')
        return render(request, 'core/product_details.html', { 
                'product': product,
                'price_history_chart': price_history_chart
            })
    else:
        messages.error(request, u'Product with code {0} was not found.'.format(code))
        return redirect(r('home'))
Пример #5
0
def product(request):
    product_code = request.GET.get('code')
    try:
        product = Product.objects.get(code=product_code)
    except Product.DoesNotExist:
        product = Product(code=product_code)
        crawler = Bloodhound()
        product = crawler.howl(product)
    if product.status == Product.OK:
        lowest_price = PriceHistory.objects.filter(product=product).order_by('price')[0]
        highest_price = PriceHistory.objects.filter(product=product).order_by('-price')[0]
        return render(request, 'api/product.html', { 
                'product': product,
                'lowest_price': lowest_price,
                'highest_price': highest_price
            })
    else:
        return render(request, 'api/product_not_found.html')
        
Пример #6
0
def product(request):
    product_code = request.GET.get('code')
    try:
        product = Product.objects.get(code=product_code)
    except Product.DoesNotExist:
        product = Product(code=product_code)
        crawler = Bloodhound()
        product = crawler.howl(product)
    if product.status == Product.OK:
        lowest_price = PriceHistory.objects.filter(
            product=product).order_by('price')[0]
        highest_price = PriceHistory.objects.filter(
            product=product).order_by('-price')[0]
        return render(
            request, 'api/product.html', {
                'product': product,
                'lowest_price': lowest_price,
                'highest_price': highest_price
            })
    else:
        return render(request, 'api/product_not_found.html')