Advertisement
benlloydjones

VMD medicines count

Jul 6th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. import os
  2. import openpyxl
  3. import re
  4.  
  5. def toLocation():
  6.     os.chdir('C:\\Users\\jonesb\\Documents\\Horrorshow')
  7.  
  8. def listFiles():
  9.     toLocation()
  10.     fileNames = os.listdir()
  11.     fileEnding = re.compile('xlsx')
  12.     for x in range(0, len(fileNames), 1):
  13.         hasEnding = fileEnding.search(fileNames[x])
  14.         if hasEnding:
  15.             pass
  16.         else:
  17.             del fileNames[x]
  18.     return fileNames
  19.  
  20. def getSheets():
  21.     toLocation()
  22.     sheetList = []
  23.     fileNames = listFiles()
  24.     for file in fileNames:
  25.         wb = openpyxl.load_workbook(file)
  26.         sheets = wb.get_sheet_names()
  27.         newSheets = []
  28.         sheetBegin = re.compile('Ref')
  29.         for x in sheets:
  30.             hasBegin = sheetBegin.search(x)
  31.             if hasBegin:
  32.                 pass                
  33.             else:
  34.                 newSheets.append(x)
  35.         sheetList.append(newSheets)
  36.     return sheetList
  37.  
  38. def counter():
  39.     premises = 0
  40.     medicines = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '10': 0, '11': 0, '12': 0, '13': 0, '14': 0, '15': 0, '16': 0, '17': 0, '18': 0, '19': 0, '20': 0, '21': 0, '22': 0, '23': 0, '24': 0, '25': 0, '26': 0, '27': 0, '28': 0, '29': 0}
  41.     sheetList = getSheets()
  42.     wbList = listFiles()
  43.     SA = re.compile('SA')
  44.     FA = re.compile('FA')
  45.     EQ = re.compile('EQ')
  46.     mSA = re.compile('10\.1\.')
  47.     mFA = re.compile('8\.1\.')
  48.     mEQ = re.compile('9\.1\.')
  49.     for x in range(0, len(sheetList), 1):
  50.         wb = openpyxl.load_workbook(wbList[x])
  51.         for y in range(0, len(sheetList[x]), 1):
  52.             premises += 1
  53.             ws = wb[sheetList[x][y]]
  54.             for z in range(1, 201, 1):
  55.                 A = ws['A' + str(z)].value
  56.                 B = ws['B' + str(z)].value
  57.                 if A is None or B is None:
  58.                     pass
  59.                 else:
  60.                     isSA = SA.search(A)
  61.                     isFA = FA.search(A)
  62.                     isEQ = EQ.search(A)
  63.                     ismSA = mSA.search(B)
  64.                     ismFA = mFA.search(B)
  65.                     ismEQ = mEQ.search(B)
  66.                     if (isSA and ismSA) or (isFA and ismFA) or (isEQ and ismEQ):
  67.                         clause = ws['B' + str(z)].value
  68.                         end = clause[5:]
  69.                         if len(end) > 2 or len(end) < 1:
  70.                             pass
  71.                         else:
  72.                             medicines[end] += 1
  73.     print(premises)
  74.     print(medicines)
  75.    
  76. counter()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement