{ elems: [ { id: 555233, n: "Agent Provocateur Maitresse", p: 346, u: "http://site.ua/555233.html", v: "Agent Provocateur", c: " " }, { id: 559675, n: "Angel Schlesser Essential for Men", p: 191, u: "http://site.ua/559675.html", v: "Angel Schlesser", c: " " } ]}
// google- var doc = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/15_W4y3GpivCjuNRWPN8HKy27MjtUeW2NTThAAPPXdkc/edit#gid=0'); // var sheet = doc.getSheetByName('parfums'); // , var i_cell = sheet.getRange('B2'); var date_cell = sheet.getRange('B3'); function main() { var i_cell_val = ( i_cell.isBlank() ) ? 0 : i_cell.getValue(); // JSON var json = JSON.parse(UrlFetchApp.fetch('http://site.ua/adwords.json').getContentText()); // var tmp = AdWordsApp.campaigns().withCondition('Name = ""').get(); var unloaded = json.elems; var export_l = unloaded.length; if(is_exported()) { Logger.log('Already exported'); return; } if (tmp.hasNext()) { var campaign = tmp.next(); } else { Logger.log('Company not found'); return; } for (i= i_cell_val; i<=export_l-1; i++) { el = unloaded[i]; var tmp = campaign.adGroups().withCondition('Name CONTAINS "__ID-' + el.id +'"').get(); if (tmp.hasNext()) { var tmp_g = tmp.next(); tmp_g.enable(); } else { var adGroupName = el.c + '_' + el.v + '_' + el.n + '__ID-' + el.id; addAdGroup(adGroupName, campaign); } i_cell.getValue(); i_cell.setValue(i); if (i == export_l-1) { date_cell.setValue(Utilities.formatDate(new Date(), "GMT+3", "dMyyyy")); i_cell.setValue(0); } } } function addAdGroup(adGroupName, ci) { var adGroup = ci.newAdGroupBuilder(); adGroup = adGroup.withName(adGroupName).withStatus("ENABLED").withKeywordMaxCpc(1).create(); } function is_exported() { var exp_date = Number(Utilities.formatDate(new Date(date_cell.getValue()), "GMT+3", "dd")); var today = Utilities.formatDate(new Date(), "GMT+3", "dd HH").split(' '); if (Number(today[1]) < 6) return true; if ( (exp_date < Number(today[0])) || date_cell.isBlank()) return false; else return true; }
function is_exported() { var exp_date = Number(Utilities.formatDate(new Date(date_cell.getValue()), "GMT+3", "dd")); var today = Utilities.formatDate(new Date(), "GMT+3", "dd HH").split(' '); if (Number(today[1]) < 6) return true; if ( (exp_date < Number(today[0])) || date_cell.isBlank()) return false; else return true; }
// google- var doc = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/15_W4y3GpivCjuNRWPN8HKy27MjtUeW2NTThAAPPXdkc/edit#gid=0'); var sheet = doc.getSheetByName('parfums'); // , var i_cell = sheet.getRange('C2'); var date_cell = sheet.getRange('C3'); function main() { var i_cell_val = ( i_cell.isBlank() ) ? 0 : i_cell.getValue(); // JSON var json = JSON.parse(UrlFetchApp.fetch('http://site.ua/adwords.json').getContentText()); // var tmp = AdWordsApp.campaigns().withCondition('Name = ""').get(); var unloaded = json.elems; var export_l = unloaded.length; if(is_exported()) { Logger.log('Already exported'); return; } if (tmp.hasNext()) { var campaign = tmp.next(); } else { Logger.log('Company not found'); return; } for (i= i_cell_val; i<=export_l-1; i++) { el = unloaded[i]; var tmp_g = campaign.adGroups().withCondition('Name CONTAINS "__ID-' + el.id +'"').get(); if (tmp_g.hasNext()) { var adGroup = tmp_g.next(); var lb = adGroup.labels().withCondition('Name = "with_text"').get(); // ADG if (!lb.hasNext()) { // ADG , adGroup.createTextAd('{KeyWord: }', ' {param1: ' + el.p + '} ', ' !', 'site.ua/' + el.v.replace(/ /g, '_'), el.u); adGroup.applyLabel('with_text'); } } else { Logger.log(" '" + el.id + "' ."); } i_cell.getValue(); i_cell.setValue(i); if (i == export_l-1) { // date_cell.setValue(Utilities.formatDate(new Date(), "GMT+3", "dMyyyy")) i_cell.setValue(0); } } } function is_exported() { var exp_date = Number(Utilities.formatDate(new Date(date_cell.getValue()), "GMT+3", "dd")); var today = Utilities.formatDate(new Date(), "GMT+3", "dd HH").split(' '); if (Number(today[1]) < 8) return true; if ( (exp_date < Number(today[0])) || date_cell.isBlank()) return false; else return true; }
// google- var doc = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/15_W4y3GpivCjuNRWPN8HKy27MjtUeW2NTThAAPPXdkc/edit#gid=0'); var sheet = doc.getSheetByName('parfums'); // , var i_cell = sheet.getRange('D2'); var date_cell = sheet.getRange('D3'); var flag_cell = sheet.getRange('D4'); function main() { var i_cell_val = ( i_cell.isBlank() ) ? 0 : i_cell.getValue(); // JSON var json = JSON.parse(UrlFetchApp.fetch('http://site.ua/adwords.json').getContentText()); // var tmp = AdWordsApp.campaigns().withCondition('Name = ""').get(); var unloaded = json.elems; var export_l = unloaded.length; if(is_exported()) { Logger.log('Already exported'); return; } if (tmp.hasNext()) { var campaign = tmp.next(); } else { Logger.log('Company not found'); return; } var flag_v = ( flag_cell.isBlank() ) ? 1 : flag_cell.getValue(); for (i= i_cell_val; i<=export_l-1; i++) { el = unloaded[i]; var tmp_g = campaign.adGroups().withCondition('Name CONTAINS "__ID-' + el.id +'"').get(); if (tmp_g.hasNext()) { var adGroup = tmp_g.next(); var key = el.n; var tmp_key = AdWordsApp.keywords().withCondition('Text = "' + key + '"').get(); // if (!tmp.hasNext()) { adGroup.createKeyword(key); } key = '[' + el.n + ']'; tmp = AdWordsApp.keywords().withCondition('Text = "' + key + '"').get(); if (!tmp.hasNext()) { adGroup.createKeyword(key); } } else { flag_v = 0; Logger.log(" '" + el.id + "' ."); } i_cell.getValue(); i_cell.setValue(i); flag_cell.setValue(flag_v); if (i == export_l-1) { // if (Number(flag_v)) // ADG date_cell.setValue(Utilities.formatDate(new Date(), "GMT+3", "dMyyyy")); i_cell.setValue(0); } } } function is_exported() { var exp_date = Number(Utilities.formatDate(new Date(date_cell.getValue()), "GMT+3", "dd")); var today = Utilities.formatDate(new Date(), "GMT+3", "dd HH").split(' '); if (Number(today[1]) < 8) return true; if ( (exp_date < Number(today[0])) || date_cell.isBlank()) return false; else return true; }
// google- var doc = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/15_W4y3GpivCjuNRWPN8HKy27MjtUeW2NTThAAPPXdkc/edit#gid=0'); var sheet = doc.getSheetByName('parfums'); // , var i_cell = sheet.getRange('E2'); var date_cell = sheet.getRange('E3'); var flag_cell = sheet.getRange('E4'); function main() { var i_cell_val = ( i_cell.isBlank() ) ? 0 : i_cell.getValue(); // JSON var json = JSON.parse(UrlFetchApp.fetch('http://site.ua/adwords.json').getContentText()); // var tmp = AdWordsApp.campaigns().withCondition('Name = ""').get(); var unloaded = json.elems; var export_l = unloaded.length; if(is_exported()) { Logger.log('Already exported'); return; } if (tmp.hasNext()) { var campaign = tmp.next(); } else { Logger.log('Company not found'); return; } var flag_v = ( flag_cell.isBlank() ) ? 1 : flag_cell.getValue(); for (i= i_cell_val; i<=export_l-1; i++) { el = unloaded[i]; var tmp_g = campaign.adGroups().withCondition('Name CONTAINS "__ID-' + el.id +'"').get(); if (tmp_g.hasNext()) { var adGroup = tmp_g.next(); var keywordIter = adGroup.keywords().get(); while (keywordIter.hasNext()) { var keyword = keywordIter.next(); keyword.setAdParam(1, el.p); } } else { flag_v = 0; Logger.log(" '" + el.id + "' ."); } i_cell.getValue(); i_cell.setValue(i); flag_cell.setValue(flag_v); if (i == export_l-1) { // if (Number(flag_v)) // ADG date_cell.setValue(Utilities.formatDate(new Date(), "GMT+3", "dMyyyy")); i_cell.setValue(0); } } } function is_exported() { var exp_date = Number(Utilities.formatDate(new Date(date_cell.getValue()), "GMT+3", "dd")); var today = Utilities.formatDate(new Date(), "GMT+3", "dd HH").split(' '); if (Number(today[1]) < 6) return true; if ( (exp_date < Number(today[0])) || date_cell.isBlank()) return false; else return true; }
function main() { var json_ids = JSON.parse(UrlFetchApp.fetch('http://site.ua/adwords.json').getContentText()).ids; var tmp = AdWordsApp.campaigns().withCondition('Name = ""').get(); if (tmp.hasNext()) { var campaign = tmp.next(); var tmp = campaign.adGroups().get(); } else { Logger.log('Company not found'); } while (tmp.hasNext()) { group = tmp.next(); name = group.getName(); id = /__ID-(\d+)$/.exec(name)[1]; if ( json_ids.indexOf(id) == -1 ) { group.pause(); } } }
i_cell.getValue();
i_cell.setValue(i);
Source: https://habr.com/ru/post/229177/
All Articles