Project

General

Profile

« Previous | Next » 

Revision 6632

dict2redmine: Use the input spreadsheet's column names and order, and pass through columns other than the term and sources columns

View differences:

dict2redmine
19 19

  
20 20
##### Redmine
21 21

  
22
def redmine_bold(text): return '*'+text+'*'
23

  
22 24
def redmine_url(text, url):
23 25
    if url: return '"'+text+'":'+url
24 26
    else: return text
......
43 45
        +' <spreadsheet term_col# sources_col# def_col# >redmine')
44 46
    term_col, sources_col, def_col = map(int, [term_col, sources_col, def_col])
45 47
    
46
    # Determine column order
48
    # Translate input
47 49
    reader = csv.reader(sys.stdin)
48
    header = reader.next()
49
    
50
    # Translate input
51 50
    writer = RedmineTableWriter(sys.stdout)
52
    writer.writerow(['*Term*', '*Sources*', '*Definition*'])
51
    writer.writerow(map(redmine_bold, reader.next())) # header
53 52
    for row in reader:
54 53
        term = row[term_col]
55 54
        sources = map(simplify_url, row[sources_col].split(source_sep))
56
        def_ = row[def_col]
57 55
        
58
        term_str = redmine_url(term, sources[0])
59
        sources_str = source_sep.join(map(source2redmine_url, sources))
56
        row[term_col] = redmine_url(term, sources[0])
57
        row[sources_col] = source_sep.join(map(source2redmine_url, sources))
60 58
        
61
        writer.writerow([term_str, sources_str, def_])
59
        writer.writerow(row)
62 60

  
63 61
main()

Also available in: Unified diff