def parse_item(self, response): data = data_extractor.extractItems(self, response, self.getters) try: print '\n\n\n\n\n',repr(data),'\n\n\n\n' worth = data_processor.extract_decimals(data['worth']) price = data_processor.extract_decimals(data['price']) savings = worth - price data['discount'] = (savings/worth)*100 except: data['discount'] = None return data
def validate_worth(self, item, spider): if item.get('worth',None): item['worth'] = data_processor.extract_decimals(item['worth']) if not item['worth']: item['worth'] = 0 else: item['worth'] = 0 # free return item
def validate_bought(self, item, spider): if item.get('bought',None): try: item['bought'] = int(data_processor.extract_decimals(item['bought'])) except: item['bought'] = 0 else: item['bought'] = 0 return item
def validate_discount(self, item, spider): if item.get('discount',None): item['discount'] = data_processor.extract_decimals(item['discount']) if not item['discount']: item['discount'] = 0 return item else: item['discount'] = 0 return item
def extractNumericXpath(hxs,xpath,index=None): return data_processor.extract_decimals(extractXpath(hxs,xpath,index))