sessionsFile = os.path.join(jobFolder, 'Sessions.txt') restrSheetFile = os.path.join(jobFolder, 'restrSheet.csv') schoolCsvFile = os.path.join(config['MASTER_FILE_PATH'], 'schoolReg.csv') schoolExportFile = os.path.join(config['MASTER_FILE_PATH'], 'schoolsExport.csv') studentCsvFile = os.path.join(config['MASTER_FILE_PATH'], 'students.csv') if not os.path.isfile(sessionsFile): sys.exit ('Sessions file not found: %s' % sessionsFile) if not os.path.isfile(restrSheetFile): sys.exit ('RestrSheet file not found: %s' % restrSheetFile) if not os.path.isfile(schoolCsvFile): sys.exit ('SchoolCsv file not found: %s' % schoolCsvFile) if not os.path.isfile(schoolExportFile): sys.exit ('SchoolExport file not found: %s' % schoolExportFile) if not os.path.isfile(studentCsvFile): sys.exit ('StudentCsv file not found: %s' % studentCsvFile) (sessionList, catagoryIndexes) = schedIO.readSessionsFile(sessionsFile) schoolInfo = schedIO.readSchoolsExport(schoolExportFile) rawEntriesList = schedIO.readSchoolWebCsv(fileName = schoolCsvFile, \ schoolInfo = schoolInfo, \ siteName = config['CONTEST_SITENAME'], \ codeChar = config['SCHOOL_CODE_CHARS']) schedIO.readStudentWebCsv (rawEntriesList, studentCsvFile) entriesList = schedIO.readRestrSheet (rawEntriesList, restrSheetFile) #Remove schools that are removed because of no entries in the restrictions sheet newSchoolInfo = [] for school in schoolInfo: Found = False for entry in entriesList: if entry['schoolId'] == school: Found = True break if not Found: schoolInfo[school]['inContest'] = False
logger.msg('Using site-specific copy of schoolsExport.csv from %s' % jobFolder) schoolExportFile = lcl_schoolExportFile elif not os.path.isfile(schoolExportFile): sys.exit('SchoolExport file not found: %s' % schoolExportFile) if os.path.isfile(lcl_studentCsvFile): logger.msg('Using site-specific copy of students.csv from %s' % jobFolder) studentCsvFile = lcl_studentCsvFile elif not os.path.isfile(studentCsvFile): sys.exit('StudentCsv file not found: %s' % studentCsvFile) (sessionList, catagoryIndexes) = schedIO.readSessionsFile(sessionsFile) schoolInfo = schedIO.readSchoolsExport(schoolExportFile) rawEntriesList = schedIO.readSchoolWebCsv(fileName = schoolCsvFile, \ schoolInfo = schoolInfo, \ siteName = config['CONTEST_SITENAME'], \ codeChar = config['SCHOOL_CODE_CHARS']) schedIO.readStudentWebCsv(rawEntriesList, studentCsvFile) entriesList = schedIO.readRestrSheet(rawEntriesList, restrSheetFile) #Remove schools that are removed because of no entries in the restrictions sheet newSchoolInfo = [] for school in schoolInfo: Found = False for entry in entriesList: if entry['schoolId'] == school: Found = True break if not Found: schoolInfo[school]['inContest'] = False
#schedIO.setLogger(logger) if 'G' in config['CONTEST_TYPE'].upper(): schedIO.setCats('group') else: schedIO.setCats('indiv') schoolInfo = schedIO.readSchoolsExport(schoolExportFile) siteCount = len(config['CONTEST_SITENAME']) for site in config['CONTEST_SITENAME']: print('Reading contest %s , File: %s' % (site, schoolCsvFile)) entriesList = schedIO.readSchoolWebCsv(fileName = schoolCsvFile, \ schoolInfo = schoolInfo, \ siteName = site, \ codeChar = 0) print('Reading contest %s , File: %s' % (site, studentCsvFile)) schedIO.readStudentWebCsv(entriesList, studentCsvFile) if len(entriesList) == 0: errMsg = '!! No entries found for contest "%s"\n' % site errMsg += '!! Double check that CONTEST_SITENAME in settings.py matches the sitename column of schoolReg.csv\n' validSites = schedIO.getSitenameList(schoolCsvFile) errMsg += '!! The list of valid sites in schoolReg.csv are:\n' for eachSite in sorted(validSites): errMsg += ' %s\n' % eachSite sys.exit(errMsg) if siteCount > 1:
if not os.path.isfile(studentCsvFile): sys.exit ('StudentCsv file not found: %s' % studentCsvFile) #Don't need logger setup unless something bad happens in the data #logger = logger.Logger(jobFolder) #schedIO.setLogger(logger) schedIO.setCats('abba') schoolInfo = schedIO.readSchoolsExport(schoolExportFile) siteCount = len(config['CONTEST_SITENAME']) for site in config['CONTEST_SITENAME']: print ('Processing %s' % site) entriesList = schedIO.readSchoolWebCsv(fileName = schoolCsvFile, \ schoolInfo = schoolInfo, \ siteName = site, \ codeChar = 0) schedIO.readStudentWebCsv (entriesList, studentCsvFile) if siteCount > 1: restrOutFile = os.path.join(jobFolder, 'restrSheet_' + site[:8] + '.csv') else: restrOutFile = os.path.join(jobFolder, 'restrSheet.csv') outFile = open (restrOutFile, 'w', newline='') writer = csv.writer (outFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow(['regId', 'schoolId', 'SchoolName', 'catShort', 'catIdx', 'entryTitle', 'inContest', 'earliestStart', 'latestEnd','performers']) for entry in entriesList: writer.writerow([entry['regId'], \ entry['schoolId'], \