You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
699 B

  1. <?php
  2. // airports.csv is from
  3. // http://ourairports.com/data/
  4. // http://ourairports.com/data/airports.csv
  5. echo "Downloading...\n";
  6. file_put_contents('airports.csv', file_get_contents('http://ourairports.com/data/airports.csv'));
  7. echo "Processing...\n";
  8. $airports = [];
  9. $fp = fopen('airports.csv', 'r');
  10. while($line = fgetcsv($fp)) {
  11. if($line[0] == 'id') {
  12. $keys = $line;
  13. continue;
  14. }
  15. if($line[13] == '') continue;
  16. $airports[$line[13]] = [];
  17. foreach($keys as $i=>$k) {
  18. $airports[$line[13]][$k] = $line[$i];
  19. }
  20. }
  21. fclose($fp);
  22. unlink('airports.csv');
  23. file_put_contents('airports.json', json_encode($airports, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
  24. echo "Done\n";