def main(locname, relLoc="./"): csv.field_size_limit(sys.maxsize) locD = geo.readIdToLoc(locname) flist = glob.glob(relLoc + '20*') fname = flist.pop() fin = csv.reader(open(fname + '/profiles.csv', 'r')) pDict = prof.builddict(fin) uin = csv.reader(open(fname + '/users.csv', 'r')) uDict = user.builddict(uin) fullR = bcr.buildRosterDict(pDict, uDict, locD) for f in flist: fin = csv.reader(open(f + '/profiles.csv', 'r')) addDict = prof.builddict(fin) uin = csv.reader(open(f + '/users.csv', 'r')) uDict = user.builddict(uin) addR = bcr.buildRosterDict(addDict, uDict, locD) for i in iter(addR): if i not in fullR: fullR[i] = addR[i] outname = relLoc + 'FullRoster.csv' bcr.writeRoster(fullR, outname)
def main(locname, relLoc="./"): csv.field_size_limit(sys.maxsize) locD = geo.readIdToLoc(locname) flist = glob.glob(relLoc + "20*") fname = flist.pop() fin = csv.reader(open(fname + "/profiles.csv", "r")) pDict = prof.builddict(fin) uin = csv.reader(open(fname + "/users.csv", "r")) uDict = user.builddict(uin) fullR = bcr.buildRosterDict(pDict, uDict, locD) for f in flist: fin = csv.reader(open(f + "/profiles.csv", "r")) addDict = prof.builddict(fin) uin = csv.reader(open(f + "/users.csv", "r")) uDict = user.builddict(uin) addR = bcr.buildRosterDict(addDict, uDict, locD) for i in iter(addR): if i not in fullR: fullR[i] = addR[i] outname = relLoc + "FullRoster.csv" bcr.writeRoster(fullR, outname)
gender = profiles[uid].gender if day not in retdict: retdict[day] = enrollday() if gender == 'm': retdict[day].m += 1 elif gender == 'f': retdict[day].f += 1 else: retdict[day].n += 1 retdict[day].t += 1 return retdict csv.field_size_limit(1000000000) f = csv.reader(open(sys.argv[1], 'r')) profdict = userprofile.builddict(f) e = csv.reader(open(sys.argv[2], 'r')) enrdict = buildenrolldict(e, profdict) it = sorted(enrdict.keys()) outfile = csv.writer(open(sys.argv[3], 'w')) mt = ft = nt = 0 outfile.writerow(['Enroll Date', 'Male', 'Female', 'Unspecified', 'Total']) for date in it: rec = enrdict[date] outfile.writerow([date, rec.m, rec.f, rec.n, rec.t]) mt += rec.m ft += rec.f nt += rec.n outfile.writerow(['', mt, ft, nt, mt + ft + nt])
'b':0, 'hs':0, 'jhs':0, 'el':0, 'none':0, 'other':0, 'unk':0 } csv.field_size_limit(1000000000) clName = sys.argv[1] ufile = utils.getFileName('user file') ufin = csv.reader(open(ufile, 'r')) profile_file = utils.getFileName('student profiles') infile = csv.reader(open(profile_file, 'r')) profiles = prof.builddict(infile) countryFile = utils.getFileName('username and country file') countryDict = makeCountryDict(ufin, countryFile) outName = raw_input("enter file name for output; nothing for stdout : ") if outName == '': outp = sys.stdout.write else: outFile = open(outName, 'w') outp = outFile.write outfile = csv.writer(open('anon'+sys.argv[1], 'w')) students = profiles.keys() for s in students: if profiles[s].gender == 'm': male += 1
from classData import user, userprofile as userp import sys import csv def split(name): """ Splits a string of form firstname lastname into two strings, returning a list containing those names. """ spIn = name.rfind(' ') first = name[ :spIn] last = name[spIn + 1: ] return [first, last] if __name__ == '__main__': csv.field_size_limit(sys.maxsize) ufile = csv.reader(open('users.csv','r')) udict = user.builddict(ufile) pfile = csv.reader(open('profiles.csv', 'r')) pdict = userp.builddict(pfile) outfile = csv.writer(open('mailAddresses.csv','w')) for uid in iter(udict): if uid in pdict: name = pdict[uid].name else : name = 'Missing Profile' [first, last] = split(name) outfile.writerow([first, last, udict[uid].email])
from classData import user from classData import certificates as cs from classData import ipGeoloc as geo if (len(sys.argv) < 2): print('Usage: buildAnonProfile.py courseName profileFile userFile countryFile certFile') sys.exit() csv.field_size_limit(1000000) out_name = sys.argv[1] + 'anonProfile.csv' o1 = csv.writer(open(out_name, 'w')) ufile = csv.reader(open(sys.argv[2], 'r')) uprof = prof.builddict(ufile) udfile = csv.reader(open(sys.argv[3], 'r')) udict = user.builddict(udfile) countryFile = csv.reader(open(sys.argv[4], 'r')) locDict = geo.builddict(countryFile) certs = False if (len(sys.argv) > 5): certfile = csv.reader(open(sys.argv[5], 'r')) certDict = cs.builddict(certfile) certs = True students = uprof.keys()
The program takes no arguments, but assumes that the files are name users.csv, profiles.csv, enrollment.csv, and produces a userDiffs.csv file. ''' import csv from classData import user from classData import userprofile as uprofile from classData import course_enrollment as ce if __name__ == '__main__': csv.field_size_limit(1000000) uIn = csv.reader(open('users.csv', 'r')) uDict = user.builddict(uIn) upIn = csv.reader(open('profiles.csv', 'r')) upDict = uprofile.builddict(upIn) ceIn = csv.reader(open('enrollment.csv', 'r')) ceDict = ce.builddict(ceIn) of = csv.writer(open('userDiffs.csv', 'w')) of.writerow(['ids in user file, not in profiles file']) for u in iter(uDict): if u not in upDict: of.writerow([u]) of.writerow(['ids in profiles file, not in user file']) for p in iter(upDict): if p not in uDict: of.writerow([p]) of.writerow(['ids in user file, not in enrollment file']) for u in iter(uDict):
rl = rosterLine(sid, name, uname, maddr, cnt, age, edu, gender) retDict[sid] = rl ofile.close() return retDict def writeRoster(rDict, filein): """ Write a roster dictionary to a .csv file Write a class roster dictionary to a .csv file named by the input parameter. """ ofile = open(filein, 'w') rf = csv.writer(ofile) rf.writerow(['Student ID', 'Name', 'User Name', 'Email', 'Country', 'Age', 'Education Level', 'Gender']) for s in iter(rDict): wl = rDict[s] rf.writerow([wl.sid, wl.name, wl.uname, wl.maddr, wl.cnt, wl.age, wl.ed, wl.gender]) ofile.close() if __name__ == '__main__': csv.field_size_limit(sys.maxsize) cl_name = sys.argv[1] proDict = profile.builddict(csv.reader(open(cl_name + '/profiles.csv', 'r'))) uDict = user.builddict(csv.reader(open(cl_name + '/users.csv', 'r'))) loc_name = sys.argv[2] locDict = geo.readIdToLoc(loc_name) rDict = buildRosterDict(proDict, uDict, locDict) writeRoster(rDict, cl_name + '/class_roster.csv')
import csv def split(name): """ Splits a string of form firstname lastname into two strings, returning a list containing those names. """ spIn = name.rfind(' ') first = name[:spIn] last = name[spIn + 1:] return [first, last] if __name__ == '__main__': csv.field_size_limit(sys.maxsize) ufile = csv.reader(open('users.csv', 'r')) udict = user.builddict(ufile) pfile = csv.reader(open('profiles.csv', 'r')) pdict = userp.builddict(pfile) outfile = csv.writer(open('mailAddresses.csv', 'w')) for uid in iter(udict): if uid in pdict: name = pdict[uid].name else: name = 'Missing Profile' [first, last] = split(name) outfile.writerow([first, last, udict[uid].email])
gender = profiles[uid].gender if day not in retdict: retdict[day]= enrollday() if gender == 'm': retdict[day].m += 1 elif gender == 'f': retdict[day].f += 1 else : retdict[day].n += 1 retdict[day].t += 1 return retdict csv.field_size_limit(1000000000) f = csv.reader(open(sys.argv[1], 'r')) profdict = userprofile.builddict(f) e = csv.reader(open(sys.argv[2], 'r')) enrdict = buildenrolldict(e, profdict) it = sorted(enrdict.keys()) outfile = csv.writer(open(sys.argv[3], 'w')) mt = ft = nt = 0 outfile.writerow(['Enroll Date', 'Male', 'Female', 'Unspecified', 'Total']) for date in it: rec = enrdict[date] outfile.writerow([date, rec.m, rec.f, rec.n, rec.t]) mt += rec.m ft += rec.f nt += rec.n outfile.writerow(['', mt, ft, nt, mt+ft+nt])