-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert.py
44 lines (31 loc) · 940 Bytes
/
convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
from xlrd import open_workbook
import csv
import os
def convert(inputfile, outputfile):
print "Converting", inputfile
book = open_workbook(inputfile)
sheet = book.sheet_by_name('mutations')
output_values = []
for r in range(sheet.nrows):
if r == 0:
header = sheet.row(r)
else:
row = sheet.row(r)
d = row[0].value.replace('-', '/')
raw_amount = row[2].value
inout = row[3].value
if inout == u'Debet':
amount = 0 - raw_amount
else:
amount = raw_amount
description = row[7].value
description = description.replace('\n', ' ')
print "Found values", d, amount, description
output_values.append([d, amount, description])
writer = csv.writer(open(outputfile, 'w'))
writer.writerows(output_values)
if __name__ == '__main__':
sources = [name for name in os.listdir(os.getcwd()) if '.xls' in name]
for source in sources:
convert(source, '%s.csv' % source[:-4])