def ImportBldgDon(selImportFn, initId=1, phase=0): xlsHdl = PyExcel(selImportFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to aceess: %s.' % selImportFn) wkSheetNm = 'Pledge' recCnt = initId # Start ID for Promissed for rec in xlsHdl.iterXlsRows(wkSheetNm): # it brings a new method: iter_rows() newRec = ['' if v is None else v for v in rec] if isValidRec(newRec): try: if phase==0: myRec = fmtPromisedRec(newRec, recCnt) else: myRec = fmtBldgDonRec(newRec, recCnt, phase) if myRec is None: continue if isinstance(myRec, list): recCnt += 1 addMsg('====>> myRec: %s' % str(myRec).encode('utf-8')) addBldDonation(myRec, len(myRec)) except Exception as e: addMsg('ERROR: Exception: %s' % e) addMsg('ERROR: ImportBldgDon: %d %s' % (recCnt, str(newRec).encode('utf-8'))) addMsg('====>> Imported Table: %s %d' % (wkSheetNm, recCnt))
def ImportDB_Org(selImportFn, impOpt=DB): xlsHdl = PyExcel(selImportFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to aceess: %s.' % selImportFn) tbllLst = xlsHdl.getAllWkSheets()[:] tbllLst.remove('Members_family') tbllLst.insert(0, 'Members_family') for wkSheetNm in tbllLst: impFcn = getImpFnc(wkSheetNm, impOpt) if impFcn is None: continue recCnt = 0 for rec in xlsHdl.iterXlsRows(wkSheetNm): # it brings a new method: iter_rows() newRec = ['' if v is None else v for v in rec] if isValidRec(newRec): recCnt += 1 try: impFcn(newRec, len(newRec)) except Exception as err: addMsg('\tERROR: %s' % err) addMsg('====>> Imported Table: %s %d' % (wkSheetNm, recCnt)) addParish() if impOpt==DB: AddFinGrps() AddAdmOpts() return selImportFn
def ImportDB(selImportFn, impOpt=DB): xlsHdl = PyExcel(selImportFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to aceess: %s.' % selImportFn) tbllLst = xlsHdl.getAllWkSheets()[:] tbllLst.remove('Members_family') tbllLst.insert(0, 'Members_family') for wkSheetNm in tbllLst: dbObj = getDbObj(wkSheetNm, impOpt) if dbObj is None: continue row = 0 hdrLst = [] for rowData in xlsHdl.iterXlsRows(wkSheetNm): # it brings a new method: iter_rows() row += 1 if row==1: hdrLst = rowData[:] else: try: recDct = dict(parseRec(rowData, hdrLst)) if isinstance(recDct, dict): a = addDbRec(dbObj, recDct) if wkSheetNm!='django_site' else addSiteId(recDct) if impOpt==WEB and wkSheetNm=='Members_family' and recDct.get('regNum')==200: break except Exception as err: print('\tERROR: ', err) addMsg('====>> Imported Table: %s %d' % (wkSheetNm, row)) #addParish() #if impOpt==DB: # AddFinGrps()s # AddAdmOpts() return selImportFn
def ExportDB(selDir): parishFn, exportFn = fmtFileNm(selDir, 'Export') xlsHdl = PyExcel(parishFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to create: %s.' % exportFn) addMsg('====>> Start exporting %s' % exportFn) #xlsHdl.clearXls() db2xls(xlsHdl) copyFile(parishFn, exportFn) return exportFn
def getMailInfo(selImportFn, prtEnvelope=True): xlsHdl = PyExcel(selImportFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to aceess: %s.' % selImportFn) reqDataLst = [] xlsWS = xlsHdl.getWkSheet() wkSheetNm = 'Pledge' recCnt = 0 for rec in xlsHdl.iterXlsRows(wkSheetNm): # it brings a new method: iter_rows() newRec = ['' if v is None else v for v in rec] reqData = getFamMailing(newRec, prtEnvelope) if isNotNull(reqData): reqDataLst.append(reqData) recCnt += 1 addMsg('====>> Total number of donation recoreds: %d' % recCnt) return reqDataLst
def SynNames(selImportFn, famNmDct): xlsHdl = PyExcel(selImportFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to aceess: %s.' % selImportFn) xlsWS = xlsHdl.getWkSheet() NameCol = Name + 1 wkSheetNm = 'Pledge' recCnt, rId = 0, 1 for rec in xlsHdl.iterXlsRows(wkSheetNm): # it brings a new method: iter_rows() newRec = ['' if v is None else v for v in rec] rId += 1 regNum = getRegNum(newRec) if isNotNull(regNum): names = famNmDct.get(regNum) if isNotNull(names): recCnt += 1 xlsWS.cell('%s%d' % (get_column_letter(NameCol), rId)).value = names newFileNm = selImportFn[:-5] + '_Updated.xlsx' xlsHdl.saveXls(newFileNm) addMsg('====>> Imported Table: %s %d' % newFileNm, recCnt)
def getNmsLst(selImportFn, reqData): xlsHdl = PyExcel(selImportFn) if xlsHdl.xlsBook is None: return addMsg('====>> ERRROR: unable to aceess: %s.' % selImportFn) fmtMethod = fmtRecNms if reqData==MemLst else getFamMailing print('====>> Processing getNmsLst: ', MemLst, reqData, fmtMethod==fmtRecNms) reqDataLst = [] xlsWS = xlsHdl.getWkSheet() wkSheetNm = 'Pledge' recCnt = 0 for rec in xlsHdl.iterXlsRows(wkSheetNm): # it brings a new method: iter_rows() newRec = ['' if v is None else v for v in rec] reqData = fmtMethod(newRec, reqData==PrtEnv) if isNotNull(reqData): reqDataLst.append(reqData) recCnt += 1 addMsg('====>> Total number of donation recoreds: %d' % recCnt) return reqDataLst