|
/****************************************** |
|
* PREREQ: |
|
* NodeJS 8+ |
|
* NPM |
|
****************************************** |
|
* USAGE: |
|
* npm install async request |
|
* node index.js |
|
******************************************/ |
|
const async = require('async') |
|
const request = require('request') |
|
const appIdList = [ |
|
// PUT APP IDs HERE |
|
] |
|
|
|
const noWeightTagList = ['Action', 'Adventure', 'Casual', 'Indie'] |
|
const poisonTagList = ['Difficult', 'Gore', 'Violent', 'Blood', 'Anime'] |
|
|
|
const fetchTagByAppId = (acc, appId, callback) => { |
|
request(`https://store.steampowered.com/app/${appId}/`, (error, response, body) => { |
|
if (error) { |
|
console.error('error:', error); // Print the error if one occurred |
|
callback(error) |
|
|
|
} else { |
|
acc[appId] = JSON.parse(`[${body.match(/({\s*"tagid"\s*:[^\}].*})/gi)[0].replace(/:true}/ig,':1}').replace(/:false}/ig,':0}')}]`) |
|
|
|
callback(null, acc) |
|
} |
|
}) |
|
} |
|
|
|
const commonTags = (tagList) => { |
|
let common = tagList[Object.keys(tagList)[0]].map((item) => item.name) |
|
|
|
Object.keys(tagList).forEach((appId) => { |
|
common = common.filter((commonItem) => { |
|
return tagList[appId].some((subItem) => subItem.name == commonItem) |
|
}) |
|
}) |
|
|
|
return common |
|
} |
|
|
|
const mostUsedTags = (tagList) => { |
|
let mostUsed = tagList[Object.keys(tagList)[0]].map((item) => { |
|
return { |
|
name: item.name, |
|
count: 0, |
|
used: 0 |
|
} |
|
}) |
|
|
|
Object.keys(tagList).forEach((appId) => { |
|
tagList[appId].forEach((subItem) => { |
|
let itemFound = mostUsed.some((mostUsedItem) => { |
|
if (mostUsedItem.name == subItem.name) { |
|
mostUsedItem.count += subItem.count |
|
mostUsedItem.used++ |
|
return true |
|
} |
|
|
|
return false |
|
}) |
|
|
|
if (!itemFound) { |
|
mostUsed.push({ |
|
name: subItem.name, |
|
count: subItem.count, |
|
used: 1 |
|
}) |
|
} |
|
}) |
|
}) |
|
|
|
mostUsed.sort((a, b) => b.used - a.used) |
|
|
|
return mostUsed.slice(0, 20) |
|
} |
|
|
|
const mostUsedTagsTop5 = (tagList) => { |
|
let mostUsed = tagList[Object.keys(tagList)[0]].map((item) => { |
|
return { |
|
name: item.name, |
|
count: 0, |
|
used: 0 |
|
} |
|
}) |
|
|
|
mostUsed = mostUsed.slice(0, 5) |
|
|
|
Object.keys(tagList).forEach((appId) => { |
|
tagList[appId].forEach((subItem, index) => { |
|
if (index > 5) { |
|
return |
|
} |
|
|
|
let itemFound = mostUsed.some((mostUsedItem) => { |
|
if (mostUsedItem.name == subItem.name) { |
|
mostUsedItem.count += subItem.count |
|
mostUsedItem.used++ |
|
return true |
|
} |
|
|
|
return false |
|
}) |
|
|
|
if (!itemFound) { |
|
mostUsed.push({ |
|
name: subItem.name, |
|
count: subItem.count, |
|
used: 1 |
|
}) |
|
} |
|
}) |
|
}) |
|
|
|
mostUsed.sort((a, b) => b.used - a.used) |
|
|
|
return mostUsed.slice(0, 5) |
|
} |
|
|
|
const filterTags = (tagList, filterArray) => { |
|
let filteredTagList = {} |
|
|
|
Object.keys(tagList).forEach((appId) => { |
|
filteredTagList[appId] = tagList[appId].filter((subItem) => { |
|
return !filterArray.includes(subItem.name) |
|
}) |
|
}) |
|
|
|
return filteredTagList |
|
} |
|
|
|
console.log('Querying tags') |
|
async.reduce(appIdList, {}, fetchTagByAppId, (err, result) => { |
|
if (err) { |
|
console.log(err) |
|
} else { |
|
let filteredResults = filterTags(result, poisonTagList) |
|
let filteredNoWeightLessResults = filterTags(result, noWeightTagList) |
|
console.log('Sorting filtered tags...') |
|
console.log({ |
|
common: commonTags(filteredNoWeightLessResults), |
|
mostUsedTagsTop5: mostUsedTagsTop5(filteredNoWeightLessResults), |
|
mostUsedTags: mostUsedTags(filteredResults) |
|
}) |
|
} |
|
}) |
What does it do?
Select several games and put their App Id in the script, then run it. It will show you:
Contribute
If you think it'll be better to make it a standalone tool please be my guest. Also I'm open to suggestion about poisonTags and weightlessTags.