Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import etree as ET
- import xlrd
- class dataVars():
- allowOneTwo = {'id', 'specific data 1', 'specific data 2'}
- allowThree = {'id', 'specific data 3', 'specific data 4', 'specific data 5', 'specific data 6'}
- dataOne = []
- dataTwo = []
- dataThree = []
- dataOneSet = []
- dataTwoSet = []
- dataThreeSet = []
- dataOneOutput = []
- dataTwoOutput = []
- def parseOne(file1):
- rows = ET.parse(file1).findall('row')
- for row in rows:
- fields = row.findall('field')
- for field in fields:
- name = field.get('name')
- if name in dataVars.allowOneTwo:
- dataVars.dataOne.append(field.text)
- def parseTwo(file2):
- rows = ET.parse(file2).findall('row')
- for row in rows:
- fields = row.findall('field')
- for field in fields:
- name = field.get('name')
- if name in dataVars.allowOneTwo:
- dataVars.dataTwo.append(field.text)
- def parseThree(file3):
- allThree = []
- rows = ET.parse(file3).findall('row')
- for row in rows:
- tempThree = {}
- fields = row.findall('field')
- for field in fields:
- name = field.get('name')
- if name in dataVars.allowThree:
- tempThree[name] = field.text
- allThree.append(tempThree)
- for item in allThree:
- if item.get('specific data 5') == 'desired value' and item.get('specific data 6') == 'desired value':
- dataVars.dataThreeSet.append(item.get('id))
- dataVars.dataThree[item.get('id')] = (item.get('specific data 3'), item.get('specific data 4')
- def prepareOut():
- for id in dataVars.dataThreeSet:
- if id not in set(dataVars.dataOne):
- dataVars.dataOneSet.append(id)
- if id not in set(dataVars.dataTwo):
- dataVars.dataTwoSet.append(id)
- def finalOut():
- for id in dataVars.dataOneSet:
- out = {
- 'ID' : '%s' % id,
- 'Field_1' : '%s' % dataVars.dataThree[id][0],
- 'Field_2' : '%s' % dataVars.dataThree[id][1]
- }
- dataVars.dataOneOutput.append(out)
- for id in dataVars.dataTwoSet:
- out = {
- 'ID' : '%s' % id,
- 'Field_1' : '%s' % dataVars.dataThree[id][0],
- 'Field_2' : '%s' % dataVars.dataThree[id][1]
- }
- dataVars.dataTwoOutput.append(out)
Advertisement
Add Comment
Please, Sign In to add comment