mrnavaone

ImportXML

May 1st, 2021
688
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PICto()
  2. {
  3.  var sheet = SpreadsheetApp.openById("1PcaHAZIcHlnC_IY4EjNOPo-3lrDV5zMcHOzmSDsVQaE");
  4.  var namesheet = sheet.getSheetByName("coffe");
  5.  namesheet.getRange("B2").copyTo(namesheet.getRange("B3"), {contentsOnly: true}); //valor anterior
  6.  namesheet.getRange("B2").clearContent().getValues();
  7.  namesheet.getRange("B4").clearContent().getValues();
  8.   namesheet.getRange("B2").setValue('TEXTO');
  9.  Utilities.sleep(2000);
  10. namesheet.getRange("B2")
  11. .setFormula('=importxml("https://www.investing.com/commodities/us-coffee-c","//*[@id=""last_last""]")');
  12. Utilities.sleep(2000);
  13. namesheet.getRange("B2").copyTo(namesheet.getRange("B4"));
  14. //copia y luego salva los cambios
  15. var id1 = '2';
  16. var id2 = '3';
  17. var info1 = coffextrac(id1, 2); //columna B3
  18. var info2 = coffextrac(id2, 2); //columna B4
  19.  
  20.  
  21.  if(info2 > info1)
  22.   {
  23.     namesheet.getRange("C9").setValue('ES MAYOR');
  24.      namesheet.getRange("C10").setValue(new Date());
  25.      var prices = "🔺 Price US Coffe$ : "+info2;
  26.      var url1 = telegramUrl + "/sendMessage?chat_id=" + "@pricecafenotify" + "&text="+ prices ; //funcion escribe en un canal.
  27.      var response = UrlFetchApp.fetch(url1);
  28.      namesheet.getRange("B3").clearContent().getValues(); //limpia valor anterior
  29. }else if(info2 < info1) {
  30.  namesheet.getRange("C9").setValue('ES MENOR');
  31.  namesheet.getRange("C10").setValue(new Date());
  32. var prices = "🔻 Price US Coffe$ : "+info2;
  33.  
  34. var dataextr = "Fuente: " +"https://www.investing.com/commodities/us-coffee-c";
  35.  
  36. var url1 = telegramUrl + "/sendMessage?chat_id=" + "@pricecafenotify" + "&text="+ prices ; //funcion escribe en un canal.
  37.  
  38. var response = UrlFetchApp.fetch(url1);
  39. namesheet.getRange("B3").clearContent().getValues(); //limpia valor anterior
  40. } else if(info2 == info1) {
  41.  namesheet.getRange("C9").setValue('ES IGUAL');
  42.  namesheet.getRange("C10").setValue(new Date());
  43. namesheet.getRange("B3").clearContent().getValues(); //limpia valor anterior
  44.  
  45. //pricecafenotify
  46. //esetests
  47. }else if(info2=='#N/A'){
  48.  namesheet.getRange("C9").setValue('ES DIFERENTE');
  49.  namesheet.getRange("C10").setValue(new Date());
  50.  
  51. namesheet.getRange("B3").clearContent().getValues(); //limpia valor anterior
  52. }
  53.  
  54. }
  55.  
RAW Paste Data