Every now and then, I’ll try to post snippets of Python code. Python is the language that I (mis)use most often. These are examples of hobbyist-level code. Also, there is a high probability that the code below will be munged up somewhat by the weblogging software.
Ben Chapman - last update 8/2007
Creates a list on standard out suitable for newaliases from a comma separated
file generated from the OPUS report 'Netids of Term Activated Stds', which is
the one that we normally get from Arnita.
For each input line, two output lines are created in the form
This way mails to NetID@law.emory.edu or to firstname.lastname@example.org
will be properly routed back to the U.
Does not currently check for duplicate LHS expressions, which is an error.
clean() should be re-written as a single regex and then it should be applied
via map or some other fanciness.
""" Do some crude clean up on the data in the CSV file by removing spaces,
periods, commas, and apostrophes. Lower-case result and return.
string = string.replace(' ','')
string = string.replace('.','')
string = string.replace(',','')
string = string.replace("'",'')
string = string.lower()
mydata = 
reader = csv.reader(open(sys.argv, "rU"))
for row in reader:
mydata = mydata[3:]
for row in mydata:
print "%s:%email@example.com" % (clean(row),clean(row))
print "%s.%s:%firstname.lastname@example.org" % (clean(row),clean(row),clean(row))
if __name__ == "__main__":
fp = open(sys.argv)
Usage: %s NAMEOFCSVFILE >NAMEOFOUTPUTFILE
Input file is a csv version of the TERM ID report from Opus.
""" % (sys.argv)