Graphe des relations d'ajout au groupe entre les membres du Million Project
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

script.py 1.6KB

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