-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-details.coffee
50 lines (42 loc) · 1.54 KB
/
get-details.coffee
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
#!/usr/bin/env coffee
cheerio = require 'cheerio'
utils = require './utils'
stats = {}
getStats = (html, url) ->
$ = cheerio.load html
byProp = (field) -> $("[itemprop='#{field}']")
getInt = (text) -> parseInt text.replace ',', ''
getOrgName = (index, item) -> $(item).attr('title')
getFollowers = ->
text = $('.stats li:nth-child(1) a').text().trim()
multiplier = if text.indexOf('k') > 0 then 1000 else 1
(parseFloat text) * multiplier
pageDesc = $('meta[name="description"]').attr('content')
userStats =
name: byProp('name').text().trim()
login: byProp('additionalName').text().trim()
location: byProp('homeLocation').text().trim()
language: (pageDesc)
gravatar: byProp('image').attr('href')
followers: getFollowers()
organizations: $('.orgs li > a').map(getOrgName)
contributions: getInt $('.contrib-day > .num').text()
contributionsStreak: getInt $('.contrib-streak > .num').text()
contributionsCurrentStreak: getInt $('.contrib-streak-current > .num').text()
stats[userStats.login] = userStats
userStats
sortStats = (stats) ->
minContributions = 1
Object.keys(stats)
.filter (login) ->
stats[login].contributions >= minContributions
.sort (a, b) ->
stats[b].contributions - stats[a].contributions
.map (login) ->
stats[login]
saveStats = ->
logins = require './temp-logins.json'
urls = logins.map (login) -> "https://github.com/#{login}"
utils.batchGet urls, getStats, ->
utils.writeStats './raw/github-users-stats.json', sortStats stats
saveStats()