forked from hugbed/ringzer0_scoreboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.js
40 lines (35 loc) · 1.08 KB
/
parser.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
"use strict";
const cheerio = require('cheerio');
const rp = require('request-promise');
const DB = require('sqlite');
const ringzero = require('./ringzero');
const pwnable = require('./pwnable');
const sites = [ {}, ringzero, pwnable ];
function getAllUsers(db) {
return db.all("SELECT id, site_id, site_user_id, name FROM USER");
}
function save(db, user, date) {
return (score) =>
db.run('INSERT INTO score_record VALUES($date, $userId, $siteId, $score)', {
$date: date,
$userId: user.id,
$siteId: user.site_id,
$score: score
});
}
function performForAllUsers(dbPath) {
const date = Date.now();
DB.open(dbPath)
.then(db =>
getAllUsers(db)
.then(users =>
Promise.all(users.map(
user => Promise.resolve(user)
.then(sites[user.site_id].fetch)
.then(sites[user.site_id].parse)
.then(save(db, user, date))
))
)
).catch(err => console.error(err));
}
module.exports.performForAllUsers = performForAllUsers;