Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import openpyxl
- import re
- def toLocation():
- os.chdir('C:\\Users\\jonesb\\Documents\\Horrorshow')
- def listFiles():
- toLocation()
- fileNames = os.listdir()
- fileEnding = re.compile('xlsx')
- for x in range(0, len(fileNames), 1):
- hasEnding = fileEnding.search(fileNames[x])
- if hasEnding:
- pass
- else:
- del fileNames[x]
- return fileNames
- def getSheets():
- toLocation()
- sheetList = []
- fileNames = listFiles()
- for file in fileNames:
- wb = openpyxl.load_workbook(file)
- sheets = wb.get_sheet_names()
- newSheets = []
- sheetBegin = re.compile('Ref')
- for x in sheets:
- hasBegin = sheetBegin.search(x)
- if hasBegin:
- pass
- else:
- newSheets.append(x)
- sheetList.append(newSheets)
- return sheetList
- def counter():
- premises = 0
- 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}
- sheetList = getSheets()
- wbList = listFiles()
- SA = re.compile('SA')
- FA = re.compile('FA')
- EQ = re.compile('EQ')
- mSA = re.compile('10\.1\.')
- mFA = re.compile('8\.1\.')
- mEQ = re.compile('9\.1\.')
- for x in range(0, len(sheetList), 1):
- wb = openpyxl.load_workbook(wbList[x])
- for y in range(0, len(sheetList[x]), 1):
- premises += 1
- ws = wb[sheetList[x][y]]
- for z in range(1, 201, 1):
- A = ws['A' + str(z)].value
- B = ws['B' + str(z)].value
- if A is None or B is None:
- pass
- else:
- isSA = SA.search(A)
- isFA = FA.search(A)
- isEQ = EQ.search(A)
- ismSA = mSA.search(B)
- ismFA = mFA.search(B)
- ismEQ = mEQ.search(B)
- if (isSA and ismSA) or (isFA and ismFA) or (isEQ and ismEQ):
- clause = ws['B' + str(z)].value
- end = clause[5:]
- if len(end) > 2 or len(end) < 1:
- pass
- else:
- medicines[end] += 1
- print(premises)
- print(medicines)
- counter()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement