Skip to content

Instantly share code, notes, and snippets.

@jonathontoon
Created August 25, 2022 10:15
Show Gist options
  • Save jonathontoon/76011883095acd5861f2e7f7c063ca51 to your computer and use it in GitHub Desktop.
Save jonathontoon/76011883095acd5861f2e7f7c063ca51 to your computer and use it in GitHub Desktop.
Script for pulling all prices for Japanese Mega Drive games from PriceCharting.com
function getAllPrices(platform = "jp-sega-mega-drive") {
const cursors = [0, 50, 100, 150, 200, 250, 300, 350, 400];
const productData = [];
cursors.forEach(function (cursor) {
const response = UrlFetchApp.fetch(`https://www.pricecharting.com/console/${platform}?sort=name&genre-name=&cursor=${cursor}&exclude-variants=false&exclude-hardware=false&format=json`);
const parsedData = JSON.parse(response.getContentText());
parsedData["products"].forEach(function (product) {
let productName = product.productName;
productName = productName.replace("Gleylancer [Reprint]", "Gleylancer Reprint");
const newPrice = product.price2 ? product.price2.trim().replace("$","") : "0.00";
const cibPrice = product.price3 ? product.price3.trim().replace("$","") : "0.00";
const loosePrice = product.price1 ? product.price1.trim().replace("$","") : "0.00";
productData.push({
"Name": productName,
"New Price (USD)": newPrice,
"CIB Price (USD)": cibPrice,
"Loose Price (USD)": loosePrice
});
});
});
const headers = Object.keys(productData[0]);
const values = productData.map(function(e) {return headers.map(function(f) {return e[f]})});
values.unshift(headers);
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment