-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtships_export.py
67 lines (52 loc) · 1.44 KB
/
tships_export.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'''
pip install pyexcel-ods
from pyexcel_ods import get_data
data = get_data("tships.ods")['tships']
###############################################
with open('tships.pck', 'w') as of:
of.write('\n'.join(';'.join(map(str, r)).replace('.0;',';').rstrip(';')+';' for r in ds[:]))
'''
from pyexcel_ods import get_data
def export(data):
data.sort()
while not data[0] or data[0][0] == 0.0:
del data[0]
for row in data[:3]:
del row[9]
del row[8]
del row[7]
del row[6]
del row[5]
del row[4]
del row[3]
del row[2]
del row[1]
del row[0]
for row in data[3:]:
if row:
del row[21]
del row[17]
del row[15]
del row[13]
del row[9]
del row[8]
del row[7]
del row[6]
del row[5]
del row[4]
del row[3]
del row[2]
del row[1]
del row[0]
def tostr(i, v):
try:
return str(int(v)) if float(v) == int(v) else str(float(v))
except:
return str(v)
with open('TShips.pck', 'w') as of:
of.write(''.join(r[0]+'\n' for r in data[0:2]))
of.write(''.join((';'.join(tostr(i, v) for i, v in enumerate(r))+';\n') for r in data[2:] if r))
if __name__ == '__main__':
xlsfile = 'tships.xls'
data = get_data("tships.ods")['tships']
export(data)