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