SmartPrice   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
dl 0
loc 29
rs 10
c 3
b 0
f 1
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 4 1
A __getattr__() 0 7 2
A sellers() 0 10 4
A parser_results() 0 3 1
1
from pysmartprice.smartparser import (
2
    PriceListParser,
3
    SearchParser,
4
    SellerParser
5
)
6
from pysmartprice.constants import SMARTPRICE_ATTRS
7
8
9
class SmartPrice(object):
10
11
    def parser_results(self, product, **kwargs):
12
        parser = PriceListParser(product, **kwargs)
13
        return parser.price_results
14
15
    def __getattr__(self, attr):
16
        if attr not in SMARTPRICE_ATTRS:
17
            msg = '{} object has no attribute {}'
18
            raise AttributeError(msg.format(self.__class__.__name__, attr))
19
20
        setattr(self, attr, self.parser_results(SMARTPRICE_ATTRS[attr]))
21
        return getattr(self, attr)
22
23
    def search(self, search_key):
24
        params = dict(s=search_key, page=1)
25
        parser = SearchParser('search', **params)
26
        return parser.price_results
27
28
    def sellers(self, product):
29
        search_res = self.search(product)
30
        products = [
31
            res for res in search_res if product.lower() in res.title.lower()]
32
33
        for product in products:
34
            seller_parser = SellerParser(product.url)
35
            setattr(product, 'sellers', seller_parser.result)
36
37
        return products
38