2
2
3
3
USER RATING ALGORITHM
4
4
5
- """
5
+ """
6
+
7
+ # importing libraries
8
+ import requests
9
+
10
+
11
+ class UserMetrics :
12
+
13
+ def __init__ (self , username ,token ):
14
+ #initialize class variables
15
+ self .username = str (username )
16
+ self .token = str (token )
17
+
18
+ #User Profile Details
19
+ self .fullName = ''
20
+ self .userID = '' #used getting avatar
21
+
22
+ #User Statistics
23
+ self .repoOwnCount = 0
24
+ self .followersCount = 0
25
+ self .followingCount = 0
26
+ self .prCount = 0
27
+ self .issueCount = 0
28
+ self .repoContributionCount = 0
29
+
30
+ #Initializing User Points
31
+ self .basePoints = 0
32
+ self .creationPoints = 0
33
+ self .contributionPoints = 0
34
+ self .activityPoints = 0
35
+ self .communityPoints = 0
36
+
37
+ #run class functions
38
+ self .fetchBasicDetails ()
39
+ #self.calcBaseScore()
40
+ #self.calcCreationScore()
41
+ #self.calcContributionScore()
42
+ #self.calcActivityScore()
43
+ #self.calcCommunityScore()
44
+
45
+ #calculate final score
46
+ #self.calcUserScore()
47
+
48
+ def fetchBasicDetails (self ):
49
+ query = """
50
+ {
51
+ user(login:""" + '"' + self .username + '"' + """)
52
+ {
53
+ name
54
+ databaseId
55
+ repositories(isFork:false)
56
+ {
57
+ totalCount
58
+ }
59
+ followers
60
+ {
61
+ totalCount
62
+ }
63
+ following
64
+ {
65
+ totalCount
66
+ }
67
+ repositoriesContributedTo
68
+ {
69
+ totalCount
70
+ }
71
+ organizations
72
+ {
73
+ totalCount
74
+ }
75
+ pullRequests
76
+ {
77
+ totalCount
78
+ }
79
+ issues
80
+ {
81
+ totalCount
82
+ }
83
+ contributionsCollection
84
+ {
85
+ totalCommitContributions
86
+ totalPullRequestContributions
87
+ totalRepositoryContributions
88
+ totalIssueContributions
89
+ totalPullRequestReviewContributions
90
+ }
91
+ }
92
+
93
+ }
94
+ """
95
+ header = {"Authorization" : "bearer " + self .token }
96
+ request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = header )
97
+ if request .status_code == 200 :
98
+ result = request .json ()
99
+ self .fullName = result ["data" ]["user" ]["name" ]
100
+ self .userID = result ["data" ]["user" ]["databaseId" ]
101
+
102
+ self .followersCount = result ["data" ]["user" ]["followers" ]["totalCount" ]
103
+ self .followingCount = result ["data" ]["user" ]["following" ]["totalCount" ]
104
+ self .prCount = result ["data" ]["user" ]["pullRequests" ]["totalCount" ]
105
+ self .issueCount = result ["data" ]["user" ]["issues" ]["totalCount" ]
106
+ self .repoOwnCount = result ["data" ]["user" ]["repositories" ]["totalCount" ]
107
+ self .repoContributionCount = result ["data" ]["user" ]["repositoriesContributedTo" ]["totalCount" ]
108
+
109
+
110
+ username = str (input ("Enter Username: " ))
111
+ token = str (input ("Enter Token: " ))
112
+
113
+ user = UserMetrics (username , token )
114
+
115
+ print ("PROFILE ANALYSIS" )
116
+ print ("Username: " + str (user .username ))
117
+ print ("Full Name: " + str (user .fullName ))
118
+ print ("\n \n STATISTICS" )
119
+ print ("Full Name: " + str (user .followersCount ))
120
+ print ("PR Count: " + str (user .prCount ))
121
+ print ("Issue Count:" + str (user .issueCount ))
122
+ print ("Repos Owned Count:" + str (user .repoOwnCount ))
123
+ print ("Repos Contributed Count:" + str (user .repoContributionCount ))
0 commit comments