Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def companies_codes(response):
- bytes = etree.fromstring(
- Environment.remove_prefix(response, '<?xml version="1.0" encoding="UTF-8"?>'),
- etree.XMLParser(huge_tree=True)
- )[0][0].text
- parser = etree.XMLParser(huge_tree=True)
- with open(os.path.join(Environment.tmp_dir, 'GetCompaniesCodes.zip'), 'wb') as fout:
- fout.write(base64.b64decode(bytes))
- with ZipFile(os.path.join(Environment.tmp_dir, 'GetCompaniesCodes.zip'), 'r') as zipObj:
- zipObj.extractall(Environment.tmp_dir)
- xml_files = []
- for filename in os.listdir(Environment.tmp_dir):
- if filename.endswith('.xml'):
- xml_files.append(
- etree.parse(os.path.join(Environment.tmp_dir, filename), parser))
- attrs = []
- for _file in xml_files:
- root = _file.getroot().find('Data')
- for company in root.iter('Company'):
- attrs.append(
- {
- 'sparkId': company.attrib.get('SparkID'),
- 'inn': company.attrib.get('INN'),
- 'ogrn': company.attrib.get('OGRN')
- }
- )
- for filename in os.listdir(Environment.tmp_dir):
- if filename.endswith('.zip') or filename.endswith('.xml'):
- os.remove(os.path.join(Environment.tmp_dir, filename))
- return attrs
Add Comment
Please, Sign In to add comment