-
Notifications
You must be signed in to change notification settings - Fork 1
/
time-slug-grid.py
executable file
·49 lines (40 loc) · 1.28 KB
/
time-slug-grid.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
#!/usr/bin/env python
from bs4 import BeautifulSoup
from click import command
from utz import *
@command()
def main():
n = now()
df = (
pd.DataFrame([
dict(
unit=u,
**{
b: c(getattr(n, u))
for b, c in { 'b62': b62, 'b64': b64, 'b90': b90 }.items()
}
)
for u in ['s', 'ds', 'cs', 'ms', 'us']
])
.set_index('unit')
)
html = df.to_html()
soup = BeautifulSoup(html, 'html.parser')
# Find the table and its header rows
table = soup.find('table')
header_rows = table.find_all('tr')[:2]
# Combine the content of the two header rows
combined_headers = []
for i in range(len(header_rows[0].find_all('th'))):
header1 = header_rows[0].find_all('th')[i].text.strip()
header2 = header_rows[1].find_all('th')[i].text.strip()
combined_header = f"{header1} {header2}".strip()
combined_headers.append(combined_header)
# Remove the second header row
header_rows[1].decompose()
# Update the first header row with the combined content
for i, th in enumerate(header_rows[0].find_all('th')):
th.string = combined_headers[i]
print(soup)
if __name__ == '__main__':
main()