Пример #1
0
    def parse_offers(self):
        offer_tree = self.yml_tree.find('.//offers')
        for offer_xml in offer_tree.findall('offer'):
            offer = Offer()
            offer.url = get_text(offer_xml.find('url'))
            offer.price = float(get_text(offer_xml.find('price'), 0.0))
            offer.oldprice = float(get_text(offer_xml.find('oldprice'), 0.0))
            offer.currencyId = get_text(offer_xml.find('currencyId'))
            offer.categoryId = get_text(offer_xml.find('categoryId'))
            for picture in offer_xml.findall('picture'):
                offer.pictures_append(get_text(picture))
            offer.store = get_text(offer_xml.find('store'), 'false')
            offer.pickup = get_text(offer_xml.find('pickup'), 'false')
            offer.delivery = get_text(offer_xml.find('delivery'), 'false')
            offer.local_delivery_cost = get_text(
                offer_xml.find('local_delivery_cost'))
            offer.name = get_text(offer_xml.find('name'))
            offer.vendor = get_text(offer_xml.find('vendor'))
            offer.vendorCode = get_text(offer_xml.find('vendorCode'))
            offer.description = get_text(offer_xml.find('description'))
            offer.sales_notes = get_text(offer_xml.find('sales_notes'))
            offer.manufacturer_warranty = get_text(
                offer_xml.find('manufacturer_warranty'))
            offer.country_of_origin = get_text(
                offer_xml.find('country_of_origin'))
            offer.age = get_text(offer_xml.find('age'))
            if not offer.age is None:
                offer.age_unit = offer_xml.find('age').attrib.get('unit', None)
            offer.barcode = get_text(offer_xml.find('barcode'))
            offer.cpa = get_text(offer_xml.find('cpa'))
            for param_xml in offer_xml.findall('param'):
                try:
                    param_value = get_text(param_xml)
                    param_name = param_xml.attrib.get('name', None)
                    if not param_value is None and not param_name is None:
                        offer.params_append(param_name=param_name,
                                            param_value=param_value)
                except AttributeError:
                    pass

            self.yml.offers_append(offer, validate=False)