Skip to content

Instantly share code, notes, and snippets.

@3gcodes
Last active August 12, 2020 20:29
Show Gist options
  • Save 3gcodes/046ed1f5bd23bb632996663553bc14fd to your computer and use it in GitHub Desktop.
Save 3gcodes/046ed1f5bd23bb632996663553bc14fd to your computer and use it in GitHub Desktop.
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://boardgamegeek.com/collection/user/gdboling';
let ids = [];
let prices = [];
foo();
console.log(prices);
async function foo() {
const response = await axios.get(url);
const data = response.data;
const $ = cheerio.load(data);
$('#collectionitems tbody tr td:nth-child(1)').each((idx, element) => {
const href = $(element).find('a').attr('href');
const id = href.split('/')[2];
ids.push(id);
});
ids.map( async id => {
console.log('calling market for id', id);
const r2 = await axios.get('https://api.geekdo.com/api/geekmarket/products?ajax=1&browsetype=browse&colluserid=0&condition=any&country=any&currency=any&displaymode=list&eventid=0&findmywants=0&inventorytype=any&marketdomain=boardgame&nosession=1&objectid=' + id + '&objecttype=thing&pageid=1&productstate=active&shiparea=any&sort=recent&stock=instock&userid=0');
const market = r2.data;
const products = market.products;
let p = 0;
products.map(product => {
try {
p = p + parseFloat(product.price);
}catch(e) {
console.log(e);
}
prices.push(p / products.length)
});
console.log('done with market for id', id);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment