Nessuna descrizione

python_repos_updated.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import requests
  2. import pygal
  3. from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
  4. # Make an API call, and store the response.
  5. url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
  6. r = requests.get(url)
  7. print("Status code:", r.status_code)
  8. # Store API response in a variable.
  9. response_dict = r.json()
  10. print("Total repositories:", response_dict['total_count'])
  11. # Explore information about the repositories.
  12. repo_dicts = response_dict['items']
  13. names, plot_dicts = [], []
  14. for repo_dict in repo_dicts:
  15. names.append(repo_dict['name'])
  16. # Get the project description, if one is available.
  17. description = repo_dict['description']
  18. if not description:
  19. description = "No description provided."
  20. plot_dict = {
  21. 'value': repo_dict['stargazers_count'],
  22. 'label': description,
  23. 'xlink': repo_dict['html_url'],
  24. }
  25. plot_dicts.append(plot_dict)
  26. # Make visualization.
  27. my_style = LS('#333366', base_style=LCS)
  28. my_style.title_font_size = 24
  29. my_style.label_font_size = 14
  30. my_style.major_label_font_size = 18
  31. my_config = pygal.Config()
  32. my_config.x_label_rotation = 45
  33. my_config.show_legend = False
  34. my_config.truncate_label = 15
  35. my_config.show_y_guides = False
  36. my_config.width = 1000
  37. chart = pygal.Bar(my_config, style=my_style)
  38. chart.title = 'Most-Starred Python Projects on GitHub'
  39. chart.x_labels = names
  40. chart.add('', plot_dicts)
  41. chart.render_to_file('python_repos.svg')