-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.js
59 lines (53 loc) · 1.58 KB
/
job.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const {
getTopProjectIDs,
getProjectDetail,
getRepoCodeFrequency,
getTrendingToday,
createProjectObject,
createTrendingDataObject,
saveAllObjects,
} = require('./task')
const { sleep } = require('./util')
const collectProject = async () => {
try {
console.log('start getting top projects...')
const ids = await getTopProjectIDs()
let projectObjects = []
for (const id of ids) {
try {
console.log(`${id}...`)
let detail = await getProjectDetail(id)
// repo code frequency
const github = detail.links.repos_url.github
if (github && github.length > 0) {
const code_frequency = await getRepoCodeFrequency(github[0])
detail = { ...detail, code_frequency }
}
projectObjects.push(createProjectObject(detail))
await sleep(1)
} catch (error) {
console.error(error)
}
}
await saveAllObjects(projectObjects)
console.log('all project saved.')
} catch (error) {
console.error(error)
}
}
const collectTrending = async () => {
try {
console.log('getting trending today...')
const items = await getTrendingToday()
await saveAllObjects(
items.map((item) => createTrendingDataObject(item))
)
console.log('all today trendings saved.')
} catch (error) {
console.error(error)
}
}
module.exports = {
collectProject,
collectTrending,
}