| Total Complexity | 8 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
| 1 | from pysmartprice.smartparser import ( |
||
| 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 |