contact_shelve = shelve.open('contact.db') contact_ufids = set(contact_shelve.keys()) # a set of ufids that will not be in the output contact_names = set(contact_shelve[contact_ufids.pop()].keys()) data_in = read_csv_fp(sys.stdin) print >>sys.stderr, len(data_in) found = 0 not_found = 0 data_out = {} for row, data in data_in.items(): new_data = dict(data) if data['UFID'] in contact_ufids: found += 1 contact_data = contact_shelve[data['UFID']] for name, value in contact_data.items(): new_data[name] = value new_data['UF_BUSINESS_FAX'] = improve_phone_number(new_data['UF_BUSINESS_FAX']) new_data['UF_BUSINESS_PHONE'] = improve_phone_number(new_data['UF_BUSINESS_PHONE']) new_data['DISPLAY_NAME'] = improve_display_name(new_data['DISPLAY_NAME']) new_data['WORKINGTITLE'] = improve_jobcode_description(new_data['WORKINGTITLE']) else: not_found += 1 for name in contact_names: new_data[name] = '' data_out[row] = new_data print >>sys.stderr, 'Found', found print >>sys.stderr, 'Not found', not_found write_csv_fp(sys.stdout, data_out) contact_shelve.close()
def test_no_op(self): in_phone = "(352) 273-8700" out_phone = improve_phone_number(in_phone) self.assertEqual(in_phone, out_phone)
def test_uf_special(self): in_phone = "3-8700" out_phone = improve_phone_number(in_phone) self.assertEqual("(352) 273-8700", out_phone)
import sys contact_shelve = shelve.open("contact.db") contact_ufids = set(contact_shelve.keys()) # a set of ufids that will not be in the output contact_names = set(contact_shelve[contact_ufids.pop()].keys()) data_in = read_csv_fp(sys.stdin) print >>sys.stderr, len(data_in) found = 0 not_found = 0 data_out = {} for row, data in data_in.items(): new_data = dict(data) if data["UFID"] in contact_ufids: found += 1 contact_data = contact_shelve[data["UFID"]] for name, value in contact_data.items(): new_data[name] = value new_data["UF_BUSINESS_FAX"] = improve_phone_number(new_data["UF_BUSINESS_FAX"]) new_data["UF_BUSINESS_PHONE"] = improve_phone_number(new_data["UF_BUSINESS_PHONE"]) new_data["DISPLAY_NAME"] = improve_display_name(new_data["DISPLAY_NAME"]) new_data["WORKINGTITLE"] = improve_jobcode_description(new_data["WORKINGTITLE"]) else: not_found += 1 for name in contact_names: new_data[name] = "" data_out[row] = new_data print >>sys.stderr, "Found", found print >>sys.stderr, "Not found", not_found write_csv_fp(sys.stdout, data_out) contact_shelve.close()