Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

extract_files.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //Declare variables
  2. var path = "Server";
  3. var fs = require('fs');
  4. var files = fs.readdirSync(path);
  5. var filenames = [files.length];
  6. //console.log("*******"+filenames);
  7. //Remove space from strings
  8. for(var i=0; i<files.length; i++)
  9. if(/\s/.test(files[i]))
  10. filenames[i] = files[i].replace(/\s/g, '');
  11. else
  12. filenames[i] = files[i];
  13. //Extract json files to local folder
  14. for(var i=0; i<files.length; i++) {
  15. //Print filenames
  16. // console.log(files[i] + " = "+filenames[i]);
  17. fs.copyFile(path+'/'+files[i], 'data/'+filenames[i], (err) => {
  18. if (err) throw err;
  19. });
  20. };
  21. /*
  22. var xmlhttp = new XMLHttpRequest();
  23. var url = "http://136.145.231.34/";
  24. xmlhttp.onreadystatechange = function() {
  25. if (this.readyState == 4 && this.status == 200) {
  26. var myArr = JSON.parse(this.responseText);
  27. myFunction(myArr);
  28. }
  29. };
  30. xmlhttp.open("GET", url, true);
  31. xmlhttp.send();
  32. function myFunction(arr) {
  33. var out = "";
  34. var i;
  35. for(i = 0; i < arr.length; i++) {
  36. out += '<a href="' + arr[i].url + '">' +
  37. arr[i].display + '</a><br>';
  38. }
  39. document.getElementById("id01").innerHTML = out;
  40. }
  41. src="http://code.jquery.com/jquery-1.11.0.min.js";
  42. (function() {
  43. var URL = "/Json/";
  44. $.getJSON( URL, {
  45. format: "json"
  46. })
  47. .done(function( data ) {
  48. $.each( data.items, function( i, item ) {
  49. //copyfile.js
  50. const fs = require('fs');
  51. // destination will be created or overwritten by default.
  52. fs.copyFile('#.json', '/JsonFiles/#.json', (err) => {
  53. if (err) throw err;
  54. console.log('File was copied to destination');
  55. });
  56. if ( i === 3 ) {
  57. return false;
  58. }
  59. });
  60. });
  61. })();
  62. */
  63. /*
  64. $.ajax({
  65. url: 'http://136.145.231.34',
  66. data: data,
  67. success: null,
  68. dataType: "json"
  69. });
  70. $.get( "ajax/test.html", function( data ) {
  71. $( ".result" ).html( data );
  72. alert( "Load was performed." );
  73. });
  74. // Assign handlers immediately after making the request,
  75. // and remember the jqxhr object for this request
  76. var jqxhr = $.get( "AROMATIZACIÓN.json", function() {
  77. alert( "success" );
  78. })
  79. .done(function() {
  80. alert( "second success" );
  81. })
  82. .fail(function() {
  83. alert( "error" );
  84. })
  85. .always(function() {
  86. alert( "finished" );
  87. });
  88. // Perform other work here ...
  89. // Set another completion function for the request above
  90. jqxhr.always(function() {
  91. alert( "second finished" );
  92. });
  93. ftp://ubuntu:BE#u3bFh@136.145.231.34/
  94. host: '136.145.231.34',
  95. username: 'ubuntu',
  96. password: 'BE#u3bFh'
  97. jquery get json
  98. */