From f0096d83a78b935cde9ce03aefd7089e7ef5a3a8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 26 Jun 2010 17:54:22 -0400 Subject: [PATCH] Filled in Graduation parsing in export_mysql --- sitecore/prof/__init__.py | 2 +- sitecore/prof/export_mysql.py | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sitecore/prof/__init__.py b/sitecore/prof/__init__.py index c78899d..d6011fb 100644 --- a/sitecore/prof/__init__.py +++ b/sitecore/prof/__init__.py @@ -98,7 +98,7 @@ class Name (AttributeHolder): fields = ['first_middle', 'last'] class Graduation (AttributeHolder): - fields = ['college', 'title', 'year'] + fields = ['college', 'field', 'title', 'year'] class Contact (AttributeHolder): fields = ['office', 'email', 'website', 'phone', 'lab', 'lab_phone'] diff --git a/sitecore/prof/export_mysql.py b/sitecore/prof/export_mysql.py index 45664c9..d022716 100644 --- a/sitecore/prof/export_mysql.py +++ b/sitecore/prof/export_mysql.py @@ -24,6 +24,7 @@ before calling prof_import. import getpass import logging +import re import MySQLdb import yaml @@ -32,6 +33,13 @@ from .. import get_logger from . import Name, Graduation, Contact, Bio, Professor +GRADUATION_REGEXP = re.compile('^(\S) +(\S), (.*) *(\d)?$') +"""Examples: + +M.S. Physics, University of Calcutta, Calcutta, India +Ph.D. Physics, University of Maryland, Maryland, 1967 +""" + class SimpleDB (object): def __init__(self, verbose=0): self.db = None @@ -166,12 +174,16 @@ Where the relevant categories are p.title += ', %s' % prof['position1'] p.graduations = [] print prof['degrees'] - for degree in prof['degrees']: - p.greaduations.append( + for degree in prof['degrees'].splitlines(): + m = GRADUATION_REGEXP.match(degree) + assert m != None, 'Misformed graduation: %s' % degree + title,field,college,year = m.groups() + p.graduations.append( Graduation( - college=None, - title=None, - year=None, + college=college, + field=field, + title=title, + year=year, ) ) p.contact = Contact( -- 2.26.2