vlr-stats-scraper 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/player-info-scraper.mjs +13 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vlr-stats-scraper",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Scrapes player stats from vlr.gg and stores them in a local SQLite database, grouped by tournament or stage.",
|
|
5
5
|
"homepage": "https://github.com/OverYander/VLR-Webscraper#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as cheerio from 'cheerio'
|
|
1
|
+
import * as cheerio from 'cheerio'
|
|
2
2
|
import { Hyperbrowser } from "@hyperbrowser/sdk"
|
|
3
|
-
import { config } from "dotenv"
|
|
3
|
+
import { config } from "dotenv"
|
|
4
4
|
|
|
5
|
-
config()
|
|
5
|
+
config()
|
|
6
6
|
|
|
7
7
|
let client;
|
|
8
8
|
function getClient() {
|
|
@@ -25,15 +25,15 @@ async function scrapePlayer(url, region) {
|
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
const $ = cheerio.load(scrapeData.data.html);
|
|
28
|
-
|
|
29
28
|
const agentsPlayed = findAgents($)
|
|
29
|
+
|
|
30
30
|
return {
|
|
31
31
|
name: getPlayerName(url),
|
|
32
32
|
team: getCurTeam($),
|
|
33
33
|
past_teams: getPastTeam($),
|
|
34
34
|
winnings: getWinnings($),
|
|
35
35
|
most_played_agents: agentsPlayed.map(data => data.Agent),
|
|
36
|
-
avg_kda: agentsPlayed.reduce((acc, data) => acc + (parseFloat(data['K:D'])) / agentsPlayed.length, 0),
|
|
36
|
+
avg_kda: agentsPlayed.reduce((acc, data) => acc + (parseFloat(data['K:D'])) / agentsPlayed.length, 0).toFixed(2),
|
|
37
37
|
nationality: getNationality($),
|
|
38
38
|
region: region,
|
|
39
39
|
stats: agentsPlayed
|
|
@@ -44,16 +44,16 @@ async function scrapePlayer(url, region) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// testing
|
|
49
48
|
/*
|
|
50
49
|
node scripts/player-info-scraper.mjs
|
|
51
50
|
*/
|
|
52
51
|
|
|
52
|
+
scrapePlayer("https://www.vlr.gg/player/939/mwzera/?timespan=all", "AMER")
|
|
53
|
+
|
|
54
|
+
|
|
53
55
|
function getPlayerName(link) {
|
|
54
|
-
// Links look like .../player/123/name/?timespan=all, so take the last path segment
|
|
55
56
|
let name = new URL(link).pathname.split('/').filter(ele => ele !== '').pop()
|
|
56
|
-
console.log(name)
|
|
57
57
|
return name
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -67,6 +67,7 @@ function findAgents($) {
|
|
|
67
67
|
const agentStats = header.next().children()
|
|
68
68
|
const agents = agentStats.map((i, el) => {
|
|
69
69
|
el = $(el)
|
|
70
|
+
// console.log('agent found:', el.children().first().find('img').attr('alt'))?.trim()
|
|
70
71
|
return {
|
|
71
72
|
agent: el.children().first().find('img').attr('alt')?.trim(),
|
|
72
73
|
stats: el.text().split('\t').map(ele => ele.trim()).filter(ele => ele !== '')
|
|
@@ -122,4 +123,6 @@ function getNationality($) {
|
|
|
122
123
|
// console.log('flags found:', $('.flag').length);
|
|
123
124
|
// console.log(header.parent().text().trim())
|
|
124
125
|
return header.parent().text().trim()
|
|
125
|
-
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default scrapePlayer
|