1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import igraph as ig
- import math
- from bs4 import BeautifulSoup
-
-
- with open('./data/html_content.html', 'r', encoding='utf-8') as fichier:
- html_content = fichier.read()
-
- def extraire_nom(entree, username=None):
- if entree.startswith("Ouzhpennet gant "):
- return entree.split("Ouzhpennet gant ")[1]
- elif entree == "Ajouté(e) par vous":
- return username
- elif entree == "Créateur du groupe":
- return None
- else:
- return None
-
- soup = BeautifulSoup(html_content, 'html.parser')
- arr = soup.get_text(separator='\n', strip=True).split('\n')[:-2]
-
- edges_as_names = [(extraire_nom(b, username='Maël Delanoë'), a) for a,b in zip(arr[:-2:2], arr[1::2])]
- vertices_as_names = list(set([i for tuple in edges_as_names for i in tuple if i is not None]))
- root = [vertices_as_names.index(child) for parent, child in edges_as_names if parent is None]
-
- 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]
- nb_vertices = len(vertices_as_names)
-
- g = ig.Graph(nb_vertices, edges_as_indexes)
- g.vs["name"] = vertices_as_names
-
- #print(g)
-
- outputfile = "./output/output_plot.png"
-
- visual_style = {}
- visual_style["vertex_size"] = 2
- visual_style["vertex_color"] = "blue"
- visual_style["vertex_label"] = g.vs["name"]
- visual_style["edge_width"] = 0.5
- visual_style["edge_arrow_width"] = 20
- visual_style["bbox"] = (2160, 1920)
- visual_style["layout"] = "rt_circular"
- visual_style["margin"] = 100
- visual_style["vertex_label_angle"] = math.pi * 1.5
- visual_style["vertex_label_dist"] = 10
- ig.plot(g, outputfile, **visual_style)
|