Advertisement
aliakbarbeda2

REPO 1

Feb 5th, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1.  
  2.  
  3. function bicah(url,awal,akhir){
  4. url = UrlFetchApp.fetch(''+url+'');
  5. awal = url.getContentText().split(''+awal+'');
  6. akhir = awal[1].split(''+akhir+'');
  7. hasil = akhir[0];
  8. }
  9.  
  10.  
  11. function bicah(i,t,c){hasil=(c=(t=i.split(""+t))[1].split(""+c))[0]}
  12. sheet_db = (SpreadsheetApp.openById("1FE8AxjzzAYsz1TSSrzm-dSfGe9gZ0e1dFGZuEOe20og")).getSheetByName("Sheet1")
  13.  
  14. function myFunction() {
  15. var startTime = new Date().getTime();
  16.  
  17. total_row = sheet_db.getLastRow()+1
  18.  
  19.  
  20. max = total_row+300;
  21. console.log("TOTAL ROW =" + total_row + " MAX = " + max + "");
  22. for(hal = total_row; hal <= max; hal=hal+1){
  23.  
  24. nomor = hal;
  25.  
  26. url = 'https://repositori.kemdikbud.go.id/'+hal+''
  27. sheet_db.appendRow([new Date(),url]);
  28.  
  29. try {
  30.  
  31. urlasli = UrlFetchApp.fetch('https://repositori.kemdikbud.go.id/'+hal+'/').getContentText()
  32. // console.log(urlasli)
  33.  
  34.  
  35. //sheet_db.getRange(sheet_db.getLastRow(),3).setValue('VALID')
  36.  
  37.  
  38. //title
  39.  
  40. bicah(urlasli,'<meta name="eprints.title" content="','"')
  41. title = hasil
  42. //console.log(hal,"="+title)
  43. sheet_db.getRange(hal,4).setValue(title)
  44.  
  45.  
  46. //penulis
  47. bicah(urlasli,'<meta name="DC.creator" content="','"');
  48. creator = hasil
  49. //console.log('penulis : '+creator)
  50. sheet_db.getRange(hal,5).setValue(creator)
  51.  
  52.  
  53. //type
  54. bicah(urlasli,'<meta name="DC.type" content="','"');
  55. type = hasil
  56. //console.log('type : '+type)
  57. sheet_db.getRange(hal,6).setValue(type)
  58.  
  59. //subject
  60. bicah(urlasli,'<meta name="DC.subject" content="','"');
  61. subject = hasil
  62. //console.log('subjek : '+subject)
  63. sheet_db.getRange(hal,7).setValue(subject)
  64.  
  65.  
  66. //date
  67. bicah(urlasli,'<meta name="DC.date" content="','"');
  68. date = hasil
  69. //console.log('date : '+date)
  70. sheet_db.getRange(hal,8).setValue(date)
  71.  
  72.  
  73.  
  74. //language
  75. bicah(urlasli,'<meta name="DC.language" content="','"');
  76. language = hasil
  77. //console.log('language : '+language)
  78. sheet_db.getRange(hal,9).setValue(language)
  79.  
  80. //pages
  81. bicah(urlasli,'<meta name="eprints.pages" content="','"')
  82. pages = hasil
  83. sheet_db.getRange(hal,10).setValue(pages)
  84.  
  85. //description
  86. bicah(urlasli,'<meta name="DC.description" content="','"');
  87. description = hasil
  88. //console.log('deskripsi : '+description)
  89. sheet_db.getRange(hal,11).setValue(description)
  90.  
  91.  
  92.  
  93. //document_url
  94. bicah(urlasli,'<meta name="eprints.document_url" content="','"');
  95. document_url = hasil
  96. //console.log('document_url : '+document_url)
  97. sheet_db.getRange(hal,12).setValue(document_url)
  98.  
  99. //SAMPUL
  100. bicah(urlasli,'class="ep_preview"><table><tr><td><img class="ep_preview_image" alt="" src="','"')
  101. preview = hasil;
  102. sheet_db.getRange(hal,13).setValue(document_url)
  103.  
  104. // dir = DriveApp.getFoldersByName('').next();
  105. // //console.log('buat file '+hal+'')
  106. // id_file = dir.createFile(''+hal+'.txt',''+cok+'').getId()
  107.  
  108.  
  109. // //console.log('LOOP = '+hal+' - VALID')
  110.  
  111.  
  112. var response = UrlFetchApp.fetch(document_url);
  113. var pdf = response.getBlob().setName(hal+".pdf");
  114. dir = DriveApp.getFoldersByName('REPO PDF NO').next();
  115. id_file = dir.createFile(pdf).getId()
  116. sheet_db.getRange(hal,14).setValue(id_file)
  117.  
  118. var pdf = response.getBlob().setName(title+".pdf");
  119. dir = DriveApp.getFoldersByName('REPO PDF TITLE').next();
  120. id_file = dir.createFile(pdf).getId()
  121. sheet_db.getRange(hal,15).setValue(id_file)
  122.  
  123.  
  124. //WEB
  125. var web = UrlFetchApp.fetch(url).getContentText()
  126. dir = DriveApp.getFoldersByName('REPO WEB').next();
  127. id_file = dir.createFile(hal+".txt", web).getId()
  128. sheet_db.getRange(hal,16).setValue(id_file)
  129.  
  130.  
  131.  
  132. // sheet_db.appendRow([new Date(),url,'VALID',title]);
  133.  
  134. // sheet_db.appendRow([new Date(),url,'VALID',title,creator,type,subject,language,description,document_url,id_file]);
  135.  
  136. // if(hal==max){
  137. // var endTime = new Date().getTime();
  138. // var duration = endTime - startTime;
  139.  
  140. // var milliseconds = parseInt((duration%1000)/100)
  141. // , seconds = parseInt((duration/1000)%60)
  142. // , minutes = parseInt((duration/(1000*60))%60);
  143.  
  144. // lapor_wa("6285217707011","REPO "+total_row+" - "+hal+" - eksekusi: " + minutes + " : " + seconds + " : " + milliseconds + "0 ")
  145. // }
  146. sheet_db.getRange(sheet_db.getLastRow(),3).setValue('VALID')
  147. } catch (error) {
  148. console.log(error)
  149. console.log('LOOP = '+hal+' - ERROR')
  150. sheet_db.getRange(sheet_db.getLastRow(),3).setValue('ERROR')
  151.  
  152. }}}
  153.  
  154.  
  155.  
  156. function createFolder() {
  157. var folderName = "";
  158. var folder = DriveApp.createFolder(folderName);
  159. Logger.log("Folder created with URL: " + folder.getUrl());
  160. }
  161.  
  162.  
  163. function buat_file(){
  164.  
  165. var response = UrlFetchApp.fetch('');
  166. var pdf = response.getBlob().setName(title+".pdf");
  167. dir = DriveApp.getFoldersByName('repo').next();
  168. dir.createFile(pdf);
  169. }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. function tes_url(){
  178. cok = UrlFetchApp.fetch('https://repositori.kemdikbud.go.id/1000').getContentText()
  179. console.log(cok)
  180. bicah(cok,'<title>','</title>')
  181. title = hasil
  182. console.log(title)
  183. sheet_db.getRange(1,4).setValue(title)
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement