Hakugin

worker - ectworker.py

Aug 20th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. from lxml import etree as ET
  2. import xlrd
  3.  
  4. class dataVars():
  5.     allowOneTwo = {'id', 'specific data 1', 'specific data 2'}
  6.     allowThree = {'id', 'specific data 3', 'specific data 4', 'specific data 5', 'specific data 6'}
  7.     dataOne = []
  8.     dataTwo = []
  9.     dataThree = []
  10.     dataOneSet = []
  11.     dataTwoSet = []
  12.     dataThreeSet = []
  13.     dataOneOutput = []
  14.     dataTwoOutput = []
  15.  
  16. def parseOne(file1):
  17.     rows = ET.parse(file1).findall('row')
  18.     for row in rows:
  19.         fields = row.findall('field')
  20.         for field in fields:
  21.             name = field.get('name')
  22.             if name in dataVars.allowOneTwo:
  23.                 dataVars.dataOne.append(field.text)
  24.  
  25. def parseTwo(file2):
  26.     rows = ET.parse(file2).findall('row')
  27.     for row in rows:
  28.         fields = row.findall('field')
  29.         for field in fields:
  30.             name = field.get('name')
  31.             if name in dataVars.allowOneTwo:
  32.                 dataVars.dataTwo.append(field.text)
  33.  
  34. def parseThree(file3):
  35.     allThree = []
  36.     rows = ET.parse(file3).findall('row')
  37.     for row in rows:
  38.         tempThree = {}
  39.         fields = row.findall('field')
  40.         for field in fields:
  41.             name = field.get('name')
  42.             if name in dataVars.allowThree:
  43.                 tempThree[name] = field.text
  44.         allThree.append(tempThree)
  45.  
  46.     for item in allThree:
  47.         if item.get('specific data 5') == 'desired value' and item.get('specific data 6') == 'desired value':
  48.             dataVars.dataThreeSet.append(item.get('id))
  49.            dataVars.dataThree[item.get('id')] = (item.get('specific data 3'), item.get('specific data 4')
  50.  
  51. def prepareOut():
  52.    for id in dataVars.dataThreeSet:
  53.        if id not in set(dataVars.dataOne):
  54.            dataVars.dataOneSet.append(id)
  55.        if id not in set(dataVars.dataTwo):
  56.            dataVars.dataTwoSet.append(id)
  57.  
  58. def finalOut():
  59.    for id in dataVars.dataOneSet:
  60.        out = {
  61.            'ID' : '%s' % id,
  62.            'Field_1' : '%s' % dataVars.dataThree[id][0],
  63.            'Field_2' : '%s' % dataVars.dataThree[id][1]
  64.        }
  65.        dataVars.dataOneOutput.append(out)
  66.  
  67.    for id in dataVars.dataTwoSet:
  68.        out = {
  69.            'ID' : '%s' % id,
  70.            'Field_1' : '%s' % dataVars.dataThree[id][0],
  71.            'Field_2' : '%s' % dataVars.dataThree[id][1]
  72.        }
  73.        dataVars.dataTwoOutput.append(out)
Advertisement
Add Comment
Please, Sign In to add comment