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

calendartoserver.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. $json_url = "http://gsx2json.com/api?id=1MxnHv59agY8gElOnaTfC34LfdIV85OwwE6CQsZXqmrA&sheet=1";
  3. $json = file_get_contents($json_url);
  4. #decode gets the json file and turns it into a php array
  5. $data = json_decode($json, TRUE);
  6. #json gives data in rows and in colums, you want it in rows
  7. $json = $data['rows'];
  8. print_r($data);
  9. echo gettype(date("m/d/y"));
  10. if (file_exists('calendar.json')){
  11. $serverjson = fopen('calendar.json', "r");
  12. $serverjson = fread($serverjson,filesize("calendar.json"));
  13. $serverjson = json_decode($serverjson,TRUE);
  14. //if the jsons are not the same
  15. if($serverjson!=$json){
  16. $serverjson = $json;
  17. $serverjson = json_encode($serverjson,TRUE);
  18. //puts the new updated json in the server
  19. unlink('calendar.json');
  20. $filename = 'calendar.json';
  21. $newfile = fopen($filename,'w');
  22. fwrite($newfile,$serverjson);
  23. fclose($newfile);
  24. //Puts the day it was updated, month/day/year
  25. $filename = ('updatedcalendar.txt');
  26. $newfile = fopen($filename,'w');
  27. $date = date("m/d/y");
  28. $time = date("h:i:sa");
  29. fwrite($newfile,"$date $time");
  30. fclose($newfile);
  31. }
  32. }
  33. #Two cases, in case the modified bit is 1 or 0 (will be diferent from the other one because it was already made with modified bit 1)
  34. #If it had modified bit 0 then try to chage its modified bit temporarily to compare
  35. // if ($serverjson['modified'] == 1){
  36. // $serverjson = json_encode($serverjson);
  37. // #if the jsons are not the same then it replaces the file
  38. // if ($serverjson != $json){
  39. // unlink('calendar.json');
  40. // #Make a new json with what you have and make a new file that is called calendar.json
  41. // $filename = 'calendar.json';
  42. // $newfile = fopen($filename,'w');
  43. // fwrite($newfile,$json);
  44. // fclose($newfile);
  45. // }
  46. // }
  47. // else{
  48. // $serverjson['modified'] = 1;
  49. // $serverjson = json_encode($serverjson);
  50. // if ($serverjson != $json){
  51. // unlink('calendar.json');
  52. // #Make a new json with what you have and make a new file that is called calendar.json
  53. // $filename = 'calendar.json';
  54. // $newfile = fopen($filename,'w');
  55. // fwrite($newfile,$json);
  56. // fclose($newfile);
  57. // }
  58. // }
  59. // #if the jsons are not the same then it replaces the file
  60. // if ($serverjson != $json){
  61. // unlink('calendar.json');
  62. // #Make a new json with what you have and make a new file that is called calendar.json
  63. // $filename = 'calendar.json';
  64. // $newfile = fopen($filename,'w');
  65. // fwrite($newfile,$json);
  66. // fclose($newfile);
  67. // }
  68. // }
  69. #--------------------------------------------------------------
  70. #print_r($data);
  71. #counts the amount of events in the google sheets that Ill use to compare with the ones in the server
  72. #echo count($data);
  73. #first one of the festival names
  74. #echo ($data[0]['nombredefestival']);
  75. #This to access the modified bit
  76. #echo ($data['modified'])
  77. #--------------------------------------------------------------
  78. else{
  79. $filename = 'calendar.json';
  80. $newfile = fopen($filename,'w');
  81. fwrite($newfile,$json);
  82. fclose($newfile);
  83. //Puts the day it was updated, month/day/year
  84. $filename = ('updatedcalendar.txt');
  85. $newfile = fopen($filename,'w');
  86. $date = date("m/d/y");
  87. $time = date("h:i:sa");
  88. fwrite($newfile,"$date $time");
  89. fclose($newfile);
  90. }
  91. ?>