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)
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 sys import utils import buildClassRoster as bcr import demographics.userprofile as prof import ipGeoloc as geo import user if __name__ == '__main__': if len(sys.argv) > 1: locname = sys.argv[1] else: locname = utils.getFileName('Enter name of the id=>location file :') csv.field_size_limit(sys.maxsize) locD = geo.readIdToLoc(locname) flist = glob.glob('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):
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')