Geen omschrijving

python_repos.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. plot_dict = {
  17. 'value': repo_dict['stargazers_count'],
  18. 'label': repo_dict['description'],
  19. 'xlink': repo_dict['html_url'],
  20. }
  21. plot_dicts.append(plot_dict)
  22. # Make visualization.
  23. my_style = LS('#333366', base_style=LCS)
  24. my_config = pygal.Config()
  25. my_config.force_uri_protocol = 'http'
  26. my_config.x_label_rotation = 45
  27. my_config.show_legend = False
  28. my_config.title_font_size = 24
  29. my_config.label_font_size = 14
  30. my_config.major_label_font_size = 18
  31. my_config.truncate_label = 15
  32. my_config.show_y_guides = False
  33. my_config.width = 1000
  34. chart = pygal.Bar(my_config, style=my_style)
  35. chart.title = 'Most-Starred Python Projects on GitHub'
  36. chart.x_labels = names
  37. chart.add('', plot_dicts)
  38. chart.render_to_file('python_repos.svg')