|
@@ -0,0 +1,47 @@
|
|
1
|
+import igraph as ig
|
|
2
|
+import math
|
|
3
|
+from bs4 import BeautifulSoup
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+with open('./data/html_content.html', 'r', encoding='utf-8') as fichier:
|
|
7
|
+ html_content = fichier.read()
|
|
8
|
+
|
|
9
|
+def extraire_nom(entree, username=None):
|
|
10
|
+ if entree.startswith("Ouzhpennet gant "):
|
|
11
|
+ return entree.split("Ouzhpennet gant ")[1]
|
|
12
|
+ elif entree == "Ajouté(e) par vous":
|
|
13
|
+ return username
|
|
14
|
+ elif entree == "Créateur du groupe":
|
|
15
|
+ return None
|
|
16
|
+ else:
|
|
17
|
+ return None
|
|
18
|
+
|
|
19
|
+soup = BeautifulSoup(html_content, 'html.parser')
|
|
20
|
+arr = soup.get_text(separator='\n', strip=True).split('\n')[:-2]
|
|
21
|
+
|
|
22
|
+edges_as_names = [(extraire_nom(b, username='Maël Delanoë'), a) for a,b in zip(arr[:-2:2], arr[1::2])]
|
|
23
|
+vertices_as_names = list(set([i for tuple in edges_as_names for i in tuple if i is not None]))
|
|
24
|
+root = [vertices_as_names.index(child) for parent, child in edges_as_names if parent is None]
|
|
25
|
+
|
|
26
|
+edges_as_indexes = [(vertices_as_names.index(parent), vertices_as_names.index(child)) for parent, child in edges_as_names if parent is not None]
|
|
27
|
+nb_vertices = len(vertices_as_names)
|
|
28
|
+
|
|
29
|
+g = ig.Graph(nb_vertices, edges_as_indexes)
|
|
30
|
+g.vs["name"] = vertices_as_names
|
|
31
|
+
|
|
32
|
+#print(g)
|
|
33
|
+
|
|
34
|
+outputfile = "./output/output_plot.png"
|
|
35
|
+
|
|
36
|
+visual_style = {}
|
|
37
|
+visual_style["vertex_size"] = 2
|
|
38
|
+visual_style["vertex_color"] = "blue"
|
|
39
|
+visual_style["vertex_label"] = g.vs["name"]
|
|
40
|
+visual_style["edge_width"] = 0.5
|
|
41
|
+visual_style["edge_arrow_width"] = 20
|
|
42
|
+visual_style["bbox"] = (2160, 1920)
|
|
43
|
+visual_style["layout"] = "rt_circular"
|
|
44
|
+visual_style["margin"] = 100
|
|
45
|
+visual_style["vertex_label_angle"] = math.pi * 1.5
|
|
46
|
+visual_style["vertex_label_dist"] = 10
|
|
47
|
+ig.plot(g, outputfile, **visual_style)
|