Skip to content

Instantly share code, notes, and snippets.

@hiroto3432
Last active December 1, 2017 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroto3432/c6876d9ab5c0c44c8def85578df8178f to your computer and use it in GitHub Desktop.
Save hiroto3432/c6876d9ab5c0c44c8def85578df8178f to your computer and use it in GitHub Desktop.
function myFunction() {
var response = UrlFetchApp.fetch("https://so2-api.mutoys.com/json/sale/all.json");
var json = JSON.parse(response.getContentText());
var id = "sheetID";
var spreadSheet = SpreadsheetApp.openById(id);
var sheet = spreadSheet.getSheetByName("シート1");
var cellx = 2;
var celly = 3;
var pitems = sheet.getRange("A3").getValue();
var price = [];
var unit = [];
var n = 0;
while(1){
try{
var item = json[n]["item_id"];
var area = json[n]["area_id"];
if(item == 106){
if(area == 2){
var p = json[n]["price"];
var u = json[n]["unit"];
price.push(p);
unit.push(u);
}
}
n++;
}
catch(e){
break;
}
}
for(var n=0; n<price.length; n++){
var value = sheet.getRange(celly + n , cellx);
value.setValue(price[n]);
value = sheet.getRange(celly + n, cellx + 1);
value.setValue(unit[n]);
}
for(var n=0; n<pitems - price.length; n++){
var values = sheet.getRange(celly + price.length + n , cellx);
values.clear();
values = sheet.getRange(celly + price.length + n , cellx + 1);
values.clear();
}
sheet.getRange("A3").setValue(price.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment