-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonProjectsMaisAv.py
More file actions
33 lines (29 loc) · 1.29 KB
/
pythonProjectsMaisAv.py
File metadata and controls
33 lines (29 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# plota o gráfico dos projetos python mais avaliados do git hub
import pygal
import requests
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
import pprint
nomes, estrelas, links = [], [], []
# requisição à API do GIT HUB
print('Solicitando dados à API...')
req = requests.get('https://api.github.com/search/repositories?q=language:python&sort=stars')
resposta = req.json() # faz um dicionário com as informações recebidas
# pprint.pprint(f"Dados solicitados pela API: \n{resposta}")
print(f"Quantidade de repositórios encontrados: {resposta['total_count']}")
itensAPI = resposta['items']
for item in itensAPI:
nomes.append(item['name']) # nomes dos projetos
estrelas.append(item['stargazers_count']) # total de estrelas
links.append(item['html_url'])
# plotagem dos dados
style = LS('#5cffff', base_style=LCS)
grafico = pygal.Bar(style=style, x_label_rotation=45) # gráfico de barras
grafico.title = 'Projetos python mais avaliados do GitHub'
grafico.x_labels = nomes # abscissas
grafico.y_title = 'Avaliações (por quantidade de estrelas)'
grafico.add("Avaliações", estrelas) # define as dicas de contexto(inseridos na barra) e o eixo das ordenadas
grafico.render_to_file('Grafico_for_git.svg')
print('Gráfico gerado!')
# links
for link in links:
print(link)