-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteTableDescriptionToIndex.py
41 lines (29 loc) · 1.04 KB
/
writeTableDescriptionToIndex.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
import os
import csv
from bs4 import BeautifulSoup
from pathlib import Path
def getTableDescription(table):
with open("../../Google Drive/Python/CSV_dump/Settlement-Tables-Descriptions.csv", "rb") as f:
reader = csv.reader(f)
for row in reader:
if row[0] == table:
return row[1]
break;
def writeToHTML():
source = "Data/settlement/index.html"
with open(source) as inf:
txt = inf.read()
soup = BeautifulSoup(txt, 'html.parser')
tables = soup.find_all('table')
table_list = tables[3]
table_names = table_list.find_all('a')
for table in table_names:
desc = getTableDescription(table.string)
mother_table = table.parent.parent
comment_section = mother_table.find_all("td", class_="comment detail")
for c in comment_section:
c.string = desc
with open("Result/settlement_table_desc/index.html","w") as file:
file.write(str(soup))
print "Done writing table description to index.html"
writeToHTML();