/
single_repository_social_mining_weighted.py
98 lines (76 loc) · 2.77 KB
/
single_repository_social_mining_weighted.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
#
# Social analysis of a single repository in GitHub
#
# Author: Massimo Menichinelli
# Homepage: http://www.openp2pdesign.org
# License: GPL v.3
#
# Requisite:
# install pyGithub with pip install PyGithub
# install NetworkX with pip install networkx
#
# PyGitHub documentation can be found here:
# https://github.com/jacquev6/PyGithub
#
from github import Github
import networkx as nx
import getpass
import os
# Clear screen
os.system('cls' if os.name=='nt' else 'clear')
from repoanalysis import analyse_repo
# Variables for the whole program
graph = nx.MultiDiGraph()
issue = {}
issue = {0:{"author":"none", "comments":{}}}
commits = {0:{"commit","sha"}}
repos = {}
if __name__ == "__main__":
print "Social Network Analisys of a GitHub repository"
print ""
userlogin = raw_input("Login: Enter your username: ")
password = getpass.getpass("Login: Enter yor password: ")
username = raw_input("Enter the username you want to analyse: ")
print ""
g = Github( userlogin, password )
print username,"has",g.get_user(username).public_repos, "repositories."
print ""
for repo in g.get_user(username).get_repos():
print "-",repo.name
print ""
repo_to_mine = raw_input("Enter the name of the repository you want to mine: ")
b = g.get_user(username).get_repo(repo_to_mine)
analyse_repo(b,graph)
# Getting rid of the node "None", it was used to catch the errors of users that are NoneType
if "None" in graph:
graph.remove_node('None')
print ""
print "NODES..."
print graph.nodes()
print ""
print "EDGES..."
print graph.edges()
print ""
print "Converting multiple edges to weighted edges..."
print ""
graph2 = nx.DiGraph()
for j in list(graph.nodes_iter(data=True)):
# copying all the nodes with their attributes
if len(j[1])>0:
graph2.add_node(j[0],collaborator=j[1]["collaborator"],contributor=j[1]["contributor"],owner=j[1]["owner"],watcher=j[1]["watcher"])
else:
graph2.add_node(j[0])
for j in list(graph.edges_iter(data=True)):
subject_id = j[0]
object_id = j[1]
if graph.has_edge(subject_id, object_id) and graph2.has_edge(subject_id, object_id):
graph2[subject_id][object_id]['weight'] += 1
elif graph.has_edge(subject_id, object_id) and not graph2.has_edge(subject_id, object_id):
graph2.add_edge(subject_id, object_id, weight=1)
print "EDGES..."
print graph2.edges()
print ""
print "Saving the network..."
nx.write_gexf(graph2, username+"_"+repo_to_mine+"_social_interactions_analysis.gexf")
print "Done. Saved as "+username+"_"+repo_to_mine+"_social_interactions_analysis.gexf"