-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (61 loc) · 1.95 KB
/
main.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
68
69
70
71
72
73
74
75
76
import sys
import codecs
from bs4 import BeautifulSoup
import os
import errno
import NamesDealer
import csv
import Play
import MyHTMLParsers
def main(argv):
maxInt = sys.maxsize
decrement = True
while decrement:
# decrease the maxInt value by factor 10
# as long as the OverflowError occurs.
decrement = False
try:
csv.field_size_limit(maxInt)
except OverflowError:
maxInt = int(maxInt/10)
decrement = True
names = []
dir = './plays/'
with open('hanochlevin.tsv', encoding="utf8") as fd:
rd = csv.DictReader(fd, delimiter="\t", quotechar='"')
for row in rd:
name = row['play'].replace(' ', '_')+'.html'
filename = dir + name
if not os.path.exists(os.path.dirname(filename)):
try:
os.makedirs(os.path.dirname(filename))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
f = open(filename, "w", encoding='utf8')
f.write(row['html'])
f.close()
names.append(name)
labels = 'all_labels'
edges = 'important'
node_colors = 'one_color'
metric = 'basic'
for arg in argv:
o,a = arg.split('=')
if o == 'labels':
labels = a
elif o == 'edges':
edges = a
elif o == 'node_colors':
node_colors = a
elif o == 'metric':
metric = a
names_dealer = NamesDealer.NamesDealer()
for name in names:
htmp = MyHTMLParsers.MyHtmlParser()
dirname = dir + name
play = Play.Play(dirname, htmp, names_dealer, labels, edges, node_colors, metric)
play.graph()
play.draw_graph()
if __name__ == '__main__':
main(sys.argv[1:])