-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_renderer.py
More file actions
executable file
·54 lines (40 loc) · 1.41 KB
/
table_renderer.py
File metadata and controls
executable file
·54 lines (40 loc) · 1.41 KB
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
#!/usr/bin/env python
import os
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
import sys
def write_error(msg):
sys.stderr.write("[E] %s\n" % msg)
def main():
if len(sys.argv) != 2:
write_error("invalid number of arguments")
return 1
csv_path = sys.argv[1]
if not os.path.exists(csv_path):
write_error("no such file: %s" % csv_path)
return 1
# expected filename is "Name-Timestamp.csv"
name, _ = os.path.splitext(os.path.basename(csv_path))
try:
py.sign_in("DemoAccount", "2qdyfjyr7o")
df = pd.read_csv(csv_path)
table_height = 0
for row_id in range(df.size/4-1):
chars_num = len(str(df.iat[row_id,0]))
cell_height = 0.893 * chars_num + 33.465
table_height += cell_height
trace = go.Table(
header=dict(values=df.columns,
fill = dict(color='#C2D4FF'),
align = ['left'] * 5),
cells=dict(values=[df.Title, df.Amount, df.Payer, df.Date],
fill = dict(color='#F5F8FF'),
align = ['left'] * 5))
data = [trace]
py.image.save_as(data, filename="%s.png" % name, scale=3, height=table_height)
except Exception as e:
write_error("caugth exception: %s" % e.message)
return 1
if __name__ == "__main__":
sys.exit(main())