Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- url = "http://www.tngtoys.ru/Go/ProductData?branch_id=138"
- url_rossosh = "http://www.tngtoys.ru/prices/PriceRossosh.xml"
- class Command(BaseCommand):
- def get_barcodes(self, tree):
- barcodes = []
- for rossosh in tree.iter('product'):
- rossosh_barcode = rossosh.find('ShtrihKod').text
- barcodes.append(rossosh_barcode)
- return barcodes
- def handle(self, *args, **options):
- response = requests.get(url, verify=False)
- tree = ElementTree.fromstring(response.content)
- response_rossosh = requests.get(url_rossosh, verify=False)
- tree_rossosh = ElementTree.fromstring(response_rossosh.content)
- print(datetime.datetime.now())
- # self.download_file(url)
- # print('Скачивание завершено')
- products = self.get_offers(tree)
- categories = self.get_categories(tree)
- barcodes = self.get_barcodes(tree_rossosh)
- i = 0
- for cat in categories:
- category = CategoryTng()
- category.category_id = cat['id']
- category.name = cat['name']
- category.save()
- for prod in products:
- current_category = int(prod['category'])
- current_barcode = prod['shtrihkod']
- if current_barcode in barcodes:
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement