def crawl(host_code, version_id): global product_api product_api = Products() options = {} log.setTag('bl-crawler-' + SPAWN_ID) log.debug('start crawl') options['host_code'] = host_code crawler = StylensCrawler(options) try: if crawler.start() == True: items = crawler.get_items() for item in items: product = {} product['name'] = item['name'] product['host_url'] = item['host_url'] product['host_code'] = item['host_code'] product['host_name'] = item['host_name'] product['product_no'] = item['product_no'] product['main_image'] = item['main_image'] product['sub_images'] = item['sub_images'] try: res = product_api.update_product_by_hostcode_and_productno( product) product['version_id'] = version_id product['product_url'] = item['product_url'] product['tags'] = item['tags'] product['price'] = item['price'] product['currency_unit'] = item['currency_unit'] product['nation'] = item['nation'] product['cate'] = item['cate'] product['sale_price'] = item['sale_price'] product['related_product'] = item['related_product'] product['thumbnail'] = item['thumbnail'] if 'upserted' in res: product_id = str(res['upserted']) log.debug("Created a product: " + product_id) product['is_processed'] = False update_product_by_id(product_id, product) elif res['nModified'] > 0: log.debug("Existing product is updated: product_no:" + product['product_no']) product['is_processed'] = False update_product_by_hostcode_and_productno(product) else: log.debug("The product is same") product['is_processed'] = True update_product_by_hostcode_and_productno(product) except Exception as e: log.error( "Exception when calling ProductApi->update_product_by_hostcode_and_productno: %s\n" % e) # delete_pod() except Exception as e: log.error("host_code:" + host_code + 'error: ' + str(e)) delete_pod() notify_to_classify(host_code) delete_pod()
from __future__ import print_function from stylelens_product.products import Products from pprint import pprint api_instance = Products() product = {} product['host_code'] = 'HC1' product['product_no'] = 'lll4' product['price'] = '1' try: api_response = api_instance.update_product_by_hostcode_and_productno(product) pprint(api_response) except Exception as e: print("Exception when calling ProductApi->update_product_by_id: %s\n" % e)