def get_variants(self, page): """Getting variants from javascript on the page. Returns three dicts ids, sizes and prices. Format of the dicts is like (key = color, value = field of (ids, sizes and prices))""" temp = page.split("// Load the product variants")[1] temp = temp.split("// Set the field to update with the product variant")[0] variants = temp.split("// Create the variant") sizes = {} ids = {} prices = {} for i in range(1, len(variants)): color = basic.get_middle_text(variants[i], "Color','", "')") if color: color = color[0] else: color = "no_color" ids = basic.add_to_dict(ids, color, basic.get_middle_text(variants[i], "setId('", "')")[0]) if variants[i].find("Size','") != -1: sizes = basic.add_to_dict(sizes, color, basic.get_middle_text(variants[i], "Size','", "')")[0]) prices = basic.add_to_dict(prices, color, basic.get_middle_text(variants[i], 'numericPrice="', '"')[0]) return ids, sizes, prices
def parse_jsons(self, jsons, color_names): """Parsing json from json urls. Returning all images in field, also returns them grouped by colors, so those groups can be used later when creating child products in xml""" images = [] images_grouped = {} for i in range(0, len(jsons)): json = urllib2.urlopen(jsons[i]).read() image = basic.get_middle_text(json, '"expressfashion/', ";") rest_of_images = basic.get_middle_text(json, ',expressfashion/', ";") temp = image + rest_of_images images_grouped = basic.add_to_dict(images_grouped, color_names[i], temp) images += temp return self.get_absolute_url(images), images_grouped