예제 #1
0
def get_trwowners():
    print "get_trwowners()"
    fn = os.path.join(os.path.dirname(__file__), 'new_data/TRWForAHRC.txt')
    f = open(fn, 'r')
    file_lines = f.readlines()
    cursor.execute('delete from domes_manor_lord86;')
    cursor.execute('delete from domes_manor_teninchief;')
    unique_names, match_names = util.get_unique_names()
    missing_lord86 = [None, '140050', '150500', '258850', '278150', '298890',\
         '322550', '373650', '39050', '405550', '414040', '519750', '554950',\
         '62450', '85555', '92360']
    missing_teninchief = [None, '10350', '10400', '106500', '106550', \
         '141150', '183350', '20150', '239550', '287950', '288050', '352600',\
         '425400', '440530', '444200', '501850', '519750', '82260', '85600',\
         '92360']
    for (counter, line) in enumerate(file_lines): 
        if counter == 0:
            continue
        else:   
            values = util.line_to_values(line,15)
            trw_id = values[0]
            structidx = values[1]
            #demesne86 = util.postgres_escape(demesne_code[values[7]])
            idxteninchief = values[13]
            if idxteninchief in missing_teninchief:
                continue
            if idxteninchief not in unique_names:
                match_found = False
                for potential_match in match_names:
                   if idxteninchief==potential_match['matchidx']:
                       idxteninchief=potential_match['unique']
                       match_found = True
                       break
                if not match_found:
                    if idxteninchief not in missing_teninchief:
                        missing_teninchief.append(idxteninchief)
            idxlord86 = values[14]
            if idxlord86 in missing_lord86:
                continue
            if (idxlord86 not in unique_names):
                match_found = False
                for potential_match in match_names:
                   if idxlord86==potential_match['matchidx']:
                       idxlord86=potential_match['unique']
                       match_found = True
                       break
                if not match_found:
                    if idxlord86 not in missing_lord86:
                        missing_lord86.append(idxlord86)
            if idxlord86:
                sql_string = "SELECT manor_id from domes_manor_lord86 WHERE manor_id="
                sql_string += structidx + " AND person_id=" + idxlord86 + ";"
                cursor.execute(sql_string)
                if not cursor.fetchall():
                    sql_string = "INSERT INTO domes_manor_lord86 (manor_id, person_id) VALUES ("
                    sql_string += structidx + ", " + idxlord86 + ");"
                    cursor.execute(sql_string)
            if idxteninchief:
                sql_string = "SELECT manor_id from domes_manor_teninchief WHERE manor_id="
                sql_string += structidx + " AND person_id=" + idxteninchief + ";"
                cursor.execute(sql_string)
                if not cursor.fetchall():
                    sql_string = "INSERT INTO domes_manor_teninchief (manor_id, person_id) VALUES ("
                    sql_string += structidx + ", " + idxteninchief + ");"
                    cursor.execute(sql_string)
    print "missing lord86s", missing_lord86
    print "missing teninchiefs", missing_teninchief
    conn.commit()
예제 #2
0
def get_treowners():
    print "get_treowners()"
    # open tab file
    fn = os.path.join(os.path.dirname(__file__), 'new_data/TREForAHRC.txt')
    f = open(fn, 'r')
    file_lines = f.readlines()
    cursor.execute('delete from domes_manor_lord66;')
    cursor.execute('delete from domes_manor_overlord66;')
    unique_names, match_names = util.get_unique_names()
    missing_lord66 = ['114700', '120750', '120810', '126950', '156850',\
               '165150', '167070', '171720', '185950', '23300', '23350',\
                '252200', '259390', '272000', '372010', '382300', '397560',\
                '399450', '431700', '476750', '48700', '495170', '519100',\
                '524260', '532050', '576050', '62450', '85500']
    missing_overlord66 = ['126950', '156850', '159250', '160400', '259380',\
                   '259390', '344560', '344670', '50650', '50830', '530050',\
                   '532050', '574150']
    for (counter, line) in enumerate(file_lines): 
        if counter == 0:
            continue
        else:   
            values = util.line_to_values(line,14)
            tre_id = values[0]
            structidx = values[1]
            if not structidx:
                continue
            idxoverlord66 = values[7]
            if idxoverlord66 in missing_overlord66:
                continue
            if idxoverlord66 is not None:
                if (idxoverlord66 not in unique_names): # if this ID isn't in our unique list
                    match_found = False
                    for potential_match in match_names: 
                       if idxoverlord66==potential_match['matchidx']:
                           idxoverlord66=potential_match['unique']
                           match_found = True
                           break
                    if not match_found:
                        #print 'match not found for idxoverlord66 ' + str(idxoverlord66)
                        if idxoverlord66 not in missing_overlord66:
                             missing_overlord66.append(idxoverlord66)
            idxlord66 = values[8]
            if idxlord66 in missing_lord66:
                continue
            if idxlord66 is not None:
                if (idxlord66 not in unique_names):
                    match_found = False
                    for potential_match in match_names:
                       if idxlord66==potential_match['matchidx']:
                           idxlord66=potential_match['unique']
                           match_found = True
                           break
                    if not match_found:
                       #missing_lord66.append(idxlord66)
                       if idxlord66 not in missing_lord66:
                            missing_lord66.append(idxlord66)
            if idxlord66:
                sql_string = "SELECT manor_id from domes_manor_lord66 WHERE manor_id="
                sql_string += structidx + " AND person_id=" + idxlord66 + ";"
                cursor.execute(sql_string)
                if not cursor.fetchall():
                    sql_string = "INSERT INTO domes_manor_lord66 (manor_id, person_id) VALUES ("
                    sql_string += structidx + ", " + idxlord66 + ");"
                    cursor.execute(sql_string)
            if idxoverlord66:
                sql_string = "SELECT manor_id from domes_manor_overlord66 WHERE manor_id="
                sql_string += structidx + " AND person_id=" + idxoverlord66 + ";"
                cursor.execute(sql_string)
                if not cursor.fetchall():
                    sql_string = "INSERT INTO domes_manor_overlord66 (manor_id, person_id) VALUES ("
                    sql_string += structidx + ", " + idxoverlord66 + ");"
                    cursor.execute(sql_string)
    print "missing lord66s", missing_lord66
    print "missing overlord66s", missing_overlord66
    conn.commit()