AUTOMATE SCRIPT

Sell Localbitcons Ads in Google sheets using Google Apps Script

				
					function getSellLocalbitcoinAds(){
  var options = {
    'method' : 'get',
    'contentType': 'application/json'
  };
  var count = 0;
  var url = 'https://localbitcoins.com/sell-bitcoins-online/ves/.json?page=1';
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sell ads');
  var lastRow = sheet.getLastRow();
  if(lastRow > 1){
    sheet.insertRowsAfter(lastRow, 1);
    sheet.deleteRows(2, lastRow-1);
  }
  do{
    var response = UrlFetchApp.fetch(url, options);
    response = JSON.parse(response.getContentText());
    var adList = response.data.ad_list;
    var completeRow = [];
    for(var i = 0; i < adList.length; i++) {
      var row = [];
      row.push(adList[i].data.trusted_required)
      row.push(adList[i].data.temp_price)
      row.push(adList[i].data.require_trusted_by_advertiser)
      row.push(adList[i].data.city)
      row.push(adList[i].data.max_amount_available)
      row.push(adList[i].data.countrycode)
      row.push(adList[i].data.online_provider)
      row.push(adList[i].data.atm_model)
      row.push(adList[i].data.created_at)
      row.push(adList[i].data.lon)
      row.push(adList[i].data.first_time_limit_btc)
      row.push(adList[i].data.is_low_risk)
      row.push(adList[i].data.is_local_office)
      row.push(adList[i].data.temp_price_usd)
      row.push(adList[i].data.bank_name)
      row.push(adList[i].data.currency)
      row.push(adList[i].data.lat)
      row.push(adList[i].data.visible)
      row.push(adList[i].data.volume_coefficient_btc)
      row.push(adList[i].data.profile.trade_count)
      row.push(adList[i].data.profile.name)
      row.push(adList[i].data.profile.last_online)
      row.push(adList[i].data.profile.feedback_score)
      row.push(adList[i].data.profile.username)
      row.push(adList[i].data.hidden_by_opening_hours)
      row.push(adList[i].data.min_amount)
      row.push(adList[i].data.payment_window_minutes)
      row.push(adList[i].data.require_identification)
      row.push(adList[i].data.require_feedback_score)
      row.push(adList[i].data.ad_id)
      row.push(adList[i].data.location_string)
      row.push(adList[i].data.limit_to_fiat_amounts)
      row.push(adList[i].data.trade_type)
      row.push(adList[i].data.max_amount)
      row.push(adList[i].data.sms_verification_required)
      row.push(adList[i].data.require_trade_volume)
      
      row.push(adList[i].actions.public_view)
      completeRow.push(row)
    }
    sheet.getRange(sheet.getLastRow()+1, 1, completeRow.length, 37).setValues(completeRow);
    //Logger.log(completeRow)
    url = response.pagination.next;
    count = count + adList.length;
  }while(response.pagination.next)
  lastRow = sheet.getLastRow();
  var SORT_DATA_RANGE = "A2:AK"+lastRow;
  Logger.log(SORT_DATA_RANGE)
  var range = sheet.getRange(SORT_DATA_RANGE);
  // Sorts by the values in column 2 (B)
  range.sort({column: 2, ascending: false});
}