-
Notifications
You must be signed in to change notification settings - Fork 9
/
sort.js
38 lines (32 loc) · 1.22 KB
/
sort.js
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
import {fs,R,S,cheerio,util} from '../common'
const objs = []
const sort = R.curry((packageName, end) => {
S.log(`Sorting results... please allow a few minutes`, {})
R.times((i) => {
const res = fs.readFileSync(`/Users/dteiml/dev/github-by-stars/dataset/${packageName}/${i}.html`, { encoding: 'utf-8' })
const $ = cheerio.load(res)
const els = $(`div.Box > div.Box-row`).toArray()
els.map(el => {
const user = $('a[data-hovercard-type="user"]', el).text()
const org = $('a[data-hovercard-type="organization"]', el).text()
const author = user || org
const repo = $('a[data-hovercard-type="repository"]', el).text()
const repoUrl = `https://github.com` + $('a[data-hovercard-type="repository"]', el).attr('href')
const noOf = $('span.text-gray-light.text-bold.pl-3', el).text()
const [stars, forks] = R.map(Number.parseInt, R.match(/\d+/g, noOf))
const a = { author, repo, repoUrl, stars, forks }
objs.push(a)
// const aLog = util.inspect(a)
// S.log(`aLog`, aLog)
})
}, end)
const sorted = R.pipe(
R.uniq,
R.sortBy(R.prop(`stars`)),
R.reverse,
R.slice(0, 10),
util.inspect,
)(objs)
S.log(`sorted`, sorted)
})
export default sort