Skip to content

Commit

Permalink
Merge pull request #71 from axi92/bug/GetInfo-for-collections
Browse files Browse the repository at this point in the history
changed GetCollection and GetInfo #70
  • Loading branch information
axi92 authored Apr 25, 2023
2 parents 1f18840 + 434d3c3 commit 8f5152c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
48 changes: 37 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SteamWorkshopScraper {
},
timeUpdated: {
selector: '.detailsStatsContainerRight > div:nth-last-child(1)',
convert: x => this.ParseSteamTime(x.replace(/Update: /), '')
convert: x => this.ParseSteamTime(x.replace(/Update: /, ''))
},
image: {
selector: '#previewImageMain',
Expand All @@ -43,6 +43,34 @@ class SteamWorkshopScraper {
}
}
this.parseCollectionInfo = {
title: 'div.workshopItemTitle:nth-child(2)',
timePublished: {
selector: 'div.rightSectionHolder:nth-child(4) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1)',
convert: x => this.ParseSteamTime(x.replace(/Update: /, ''))
},
timeUpdated: {
selector: 'div.rightSectionHolder:nth-child(4) > div:nth-child(1) > div:nth-child(2) > div:nth-child(2)',
convert: x => this.ParseSteamTime(x.replace(/Update: /, ''))
},
image: {
selector: '#CollectionBackgroundImage',
attr: 'src'
},
data: {
listItem: ".collectionItem",
data: {
id: {
selector: 'div.collectionItemDetails > a:nth-child(1)',
attr: 'href',
convert: x => x.replace(/(.*)\=/g, '')
}
},
convert: x => {
return parseInt(x.id);
}
}
}
this.parseCollectionOrNot = {
data: {
listItem: ".collectionItem",
data: {
Expand Down Expand Up @@ -91,9 +119,13 @@ class SteamWorkshopScraper {
}));
}

GetInfo(id) {
// console.log('Getinfo', id)
return this.Scrape(this.workShopUrlInfo + id.toString(), this.parseSettingsInfo);
async GetInfo(id) {
let checkCollection = await this.Scrape(this.workShopUrlInfo + id.toString(), this.parseCollectionOrNot)
if(checkCollection.data.length > 0){ // is collection
return this.Scrape(this.workShopUrlInfo + id.toString(), this.parseCollectionInfo);
} else { // is single mod
return this.Scrape(this.workShopUrlInfo + id.toString(), this.parseSettingsInfo);
}
}

GetChangeLog(id) {
Expand All @@ -104,13 +136,7 @@ class SteamWorkshopScraper {
let that = this;
return new Promise(async function(resolve, reject) {
let data = await that.Scrape(that.workShopUrlInfo + id.toString(), that.parseCollectionInfo);
// console.log(data)
data = data.data;
let dataArray = [];
for (var i = 0; i < data.length; i++) {
dataArray.push(data[i].id);
}
resolve(dataArray);
resolve(data);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steam-workshop-scraper",
"version": "0.0.6",
"version": "0.0.7",
"description": "Gets data about Steam workshop mods/assets",
"main": "index.js",
"scripts": {
Expand Down
22 changes: 16 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const SteamWorkshopScraper = require('../index.js');
const sws = new SteamWorkshopScraper('Universal');
var assert = require('assert');
const { DateTime } = require("luxon");
const {
DateTime
} = require("luxon");

describe('SteamWorkshopScraper', function () {
it('should show 18 entries', async function () {
await sws.GetCollection(1608290482).then(function (data) { // old collection, hope nobody will ever change this collection
sws.AddToUpdates(data);
await sws.GetCollection(1608290482).then(function (collection) { // old collection, hope nobody will ever change this collection
sws.AddToUpdates(collection.data);
// console.log(sws.workshopMap);
assert.equal(data.length, 18);
assert.equal(collection.data.length, 18);
});
});

Expand Down Expand Up @@ -48,7 +50,7 @@ describe('SteamWorkshopScraper', function () {

it('TriggerUpdate and check title from one item', async function () {
await sws.TriggerUpdate().then(function () {
assert.equal(sws.workshopMap.get('1999447172').title, 'Super Structures');
assert.equal(sws.workshopMap.get(1999447172).title, 'Super Structures');
});
});

Expand Down Expand Up @@ -87,4 +89,12 @@ describe('SteamWorkshopScraper', function () {
assert.equal(data.image, 'https://steamuserimages-a.akamaihd.net/ugc/421440386976795132/B34EDDA953337D1CD05DBE82BAAA397B0520AB50/?imw=268&imh=268&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=true');
});
});
});

it('GetInfo on collection', async function () {
await sws.GetInfo(1608290482).then(function (data) {
assert.equal(data.title, 'ark mods');
assert.equal(data.data.length, 18);
});
});

});

0 comments on commit 8f5152c

Please sign in to comment.