Revision 734
Added by Aaron Marcuse-Kubitza almost 13 years ago
join | ||
---|---|---|
2 | 2 |
# Inner-joins two map spreadsheets A->B and B->C to A->C |
3 | 3 |
|
4 | 4 |
import csv |
5 |
import os.path |
|
5 | 6 |
import sys |
6 | 7 |
|
7 |
def merge_rows(*rows): |
|
8 |
'''e.g. ['a','b'] + ['','y','z'] = ['a','b; y','z']''' |
|
9 |
def get(row, i): |
|
10 |
try: return row[i] |
|
11 |
except IndexError: return '' |
|
12 |
return ['; '.join(filter(lambda v: v != '', [get(row, i) for row in rows])) |
|
13 |
for i in xrange(max(map(len, rows)))] |
|
8 |
sys.path.append(os.path.dirname(__file__)+"/../lib") |
|
14 | 9 |
|
10 |
import maps |
|
11 |
|
|
15 | 12 |
def main(): |
16 | 13 |
try: _prog_name, map_1_path = sys.argv |
17 | 14 |
except ValueError: |
... | ... | |
40 | 37 |
try: |
41 | 38 |
new = map_1[row[1]] |
42 | 39 |
row[1] = new[1] # mapping |
43 |
row[2:] = merge_rows(row[2:], new[2:]) # comments |
|
40 |
row[2:] = maps.merge_rows(row[2:], new[2:]) # comments
|
|
44 | 41 |
except KeyError: |
45 | 42 |
row[2] = '** No join mapping for '+row[1]+' ** '+row[2] |
46 | 43 |
row[1] = '' |
Also available in: Unified diff
join: Use merge_rows() from new maps.py