Skip to content

Instantly share code, notes, and snippets.

@leag
Created August 22, 2018 19:29
Show Gist options
  • Select an option

  • Save leag/e94253ecad127b2c078ff3b9b66e9931 to your computer and use it in GitHub Desktop.

Select an option

Save leag/e94253ecad127b2c078ff3b9b66e9931 to your computer and use it in GitHub Desktop.
Google Apps Script for www.abugames.com
function getPrice(name,set, cond) {
var price = 0;
cond = encodeURIComponent(cond);
var url = 'https://data.abugames.com/solr/nodes/select?facet.mincount=1&facet.limit=-1&facet=on&indent=on&q=*:*&fq=%2Bcategory%3A%22Magic%20the%20Gathering%20Singles%22%20%2Bdisplay_title%3A%22' + encodeURIComponent(name) +'%22%20%2Bmagic_edition%3A%22'+ encodeURIComponent(set) + '%22%20%2Blanguage%3A%22English%22%20-offline_item%3Atrue%20OR%20-title%3A%22STORE%22%20OR%20-price%3A0%20%2B((%2Bquantity%3A%5B1%20TO%20*%5D)%20OR%20(%2Bquantity%3A0%20%2Balways_show_inventory%3A1))%20&rows=100&wt=json'
var content = JSON.parse(UrlFetchApp.fetch(url).getContentText());
if (content.response.numFound > 0 )
{
var arrlength = content.response.docs.length;
for ( var i = 0; i < arrlength; i++){
var condition = content.response.docs[i].condition;
if(condition == cond) {
price = content.response.docs[i].price;
return price;
Logger.log(price);
}
}
}
Logger.log(content);
}
function urlABU(url) {
url = url.replace('https://abugames.com/magic-the-gathering/singles/product-detail/','');
url = url.split('/').slice(0,2)
if (url.length == 2 ){
var nombre = decodeURIComponent(decodeURIComponent(url[0].replace(/-/g,' ')));
var set = decodeURIComponent(decodeURIComponent(url[1].replace(/-/g,' ')));
return [[nombre,set]];
}
Logger.log(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment