-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExeGitHub.py (versao antiga)
83 lines (56 loc) · 1.89 KB
/
ExeGitHub.py (versao antiga)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# coding: utf-8
import json
import urllib2
import sys
def obterNomeSeguidor(nomeSeguidor):
dadosSeguidores = []
API = 'https://api.github.com/users/{0}'
url_processada = API.format(nomeSeguidor)
textoJson = verificarJSONExistente(url_processada)
textoJsonProcessado = json.loads(textoJson)
return textoJsonProcessado['name']
def obterRepositorios(nomeSeguidor):
nomes = []
API = 'https://api.github.com/users/{0}/repos'
url_processada = API.format(nomeSeguidor)
textoJson = verificarJSONExistente(url_processada)
textoJsonProcessado = json.loads(textoJson)
for repositorio in textoJsonProcessado:
nomes.append(repositorio['name'])
return nomes
def verificarJSONExistente(linkAPI):
try:
arquivo = open(linkAPI.replace('/', '-') + '.txt', 'r')
textoJson = arquivo.read()
print 'entrei aqui'
return textoJson
except Exception:
try:
arq = open(linkAPI.replace('/', '-') + '.txt', 'w')
textoJson = urllib2.urlopen(linkAPI).read()
arq.write(textoJson)
arq.close()
return textoJson
except Exception:
print 'Deu exceção linha 42'
API = 'https://api.github.com/users/{0}'
usuario = raw_input('Nome do usuario GitHub: ')
linkAPI = API.format(usuario)
textoJson = verificarJSONExistente(linkAPI)
textoJsonProcessado = json.loads(textoJson)
urlUsuarios = textoJsonProcessado['followers_url']
textoUrlProcessado = verificarJSONExistente(urlUsuarios)
usuariosJson = json.loads(textoUrlProcessado)
contadorSeguidores = textoJsonProcessado['followers']
print 'Usuário da Consulta: ', textoJsonProcessado['name'], '\n'
print contadorSeguidores, ' seguidores: ', '\n'
contUsuarios = 0
contRepositorios = 0
for usuario in usuariosJson:
nome = usuario['login']
print obterNomeSeguidor(nome), ' ', contUsuarios+1, '\n'
for repositorio in obterRepositorios(nome):
print '\t', repositorio, ' ', contRepositorios+1
contRepositorios += 1
print '\n'
contUsuarios += 1