SHARE
TWEET

Get updates for TIA Portal [SIEMENS]

DeaD_EyE Sep 1st, 2018 (edited) 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from itertools import chain
  2. from urllib.request import urlopen
  3. import json
  4. import sys
  5.  
  6. try:
  7.     from lxml.etree import fromstring
  8. except:
  9.     print('Please install with pip lxml')
  10.     print('pip install lxml')
  11.     sys.exit(1)
  12.  
  13.  
  14. def get_product_updates():
  15.     base = 'https://update.industry.siemens.com/asu/files/tiaportal/'
  16.     xml = 'UpdatesSummaryCatalog.xml'
  17.     xml_data = urlopen(base + xml).read()
  18.     et = fromstring(xml_data)
  19.  
  20.     for product in et.findall('Updates/Product'):
  21.         try:
  22.             name = product.xpath('DisplayName')[0].text
  23.             path = product.xpath('Path')[0].text.replace('[MAINURL]', base)
  24.             siwa = product.xpath('SiWA')[0].text
  25.             file = path + siwa
  26.             cabs = []
  27.             for cab in product.xpath('CabFile'):
  28.                if cab.text:
  29.                    cabs.append(base + cab.text)
  30.         except (IndexError, TypeError):
  31.             continue
  32.         else:
  33.             yield {'name': name, 'files': list(chain([file], cabs))}
  34.  
  35. if __name__ == '__main__':
  36.     print(json.dumps(list(get_product_updates()), indent=4))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top