Advertisement
destenation01

Untitled

Jul 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. url = "http://www.tngtoys.ru/Go/ProductData?branch_id=138"
  2. url_rossosh = "http://www.tngtoys.ru/prices/PriceRossosh.xml"
  3.  
  4.  
  5. class Command(BaseCommand):
  6.  
  7.     def get_barcodes(self, tree):
  8.         barcodes = []
  9.  
  10.         for rossosh in tree.iter('product'):
  11.             rossosh_barcode = rossosh.find('ShtrihKod').text
  12.  
  13.             barcodes.append(rossosh_barcode)
  14.  
  15.         return barcodes
  16.  
  17.     def handle(self, *args, **options):
  18.         response = requests.get(url, verify=False)
  19.         tree = ElementTree.fromstring(response.content)
  20.  
  21.         response_rossosh = requests.get(url_rossosh, verify=False)
  22.         tree_rossosh = ElementTree.fromstring(response_rossosh.content)
  23.  
  24.         print(datetime.datetime.now())
  25.         # self.download_file(url)
  26.         # print('Скачивание завершено')
  27.         products = self.get_offers(tree)
  28.         categories = self.get_categories(tree)
  29.         barcodes = self.get_barcodes(tree_rossosh)
  30.         i = 0
  31.  
  32.         for cat in categories:
  33.             category = CategoryTng()
  34.             category.category_id = cat['id']
  35.             category.name = cat['name']
  36.             category.save()
  37.         for prod in products:
  38.             current_category = int(prod['category'])
  39.             current_barcode = prod['shtrihkod']
  40.  
  41.             if current_barcode in barcodes:
  42.                 i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement