-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (46 loc) · 1.33 KB
/
index.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
const cloudscraper = require('cloudscraper');
const knex = require('knex');
const knexConnection = knex({
client: `mysql2`,
connection: {
host: ``,
user: ``,
password: ``,
database: ``
}
});
let counter = 0;
function iterate() {
function subIterate(rows, subOffset = 0) {
if (subOffset < rows.length) {
return cloudscraper.get(rows[subOffset].cursehref).then(result => {
const id = result.match(/href="\/project\/([0-9]+)\/license"/i);
knexConnection('dle_post')
.where('id', rows[subOffset].id)
.update(`curseID`, id[1])
.then(result => {
console.log(`Updated: ${counter}, current id: ${id[1]}`);
counter++;
subIterate(rows, ++subOffset);
})
}).catch(error => {
if (error.statusCode !== 404) {
throw new Error('Me ded, sir. Me is sorri.');
}
console.log(`Whoops, this link is gay: ${rows[subOffset].cursehref}`);
subIterate(rows, ++subOffset);
});
}
iterate();
}
knexConnection(`dle_post`)
.select(['id', 'cursehref', 'curseID'])
.where('cursehref', 'LIKE', 'https%')
.whereNull('curseID')
.limit(5000)
.then(result => {
console.log(`Fetched ${result.length} posts. Let's get started:`);
subIterate(result);
});
}
iterate();