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.

45 lines
746 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. $data = [
  17. $line[13], // Code
  18. $line[4], // Latitude
  19. $line[5], // Longitude
  20. $line[3], // Name
  21. ];
  22. $airports[] = $data;
  23. }
  24. fclose($fp);
  25. unlink('airports.csv');
  26. $fp = fopen('airports-compact.csv', 'w');
  27. foreach($airports as $line) {
  28. fputcsv($fp, $line);
  29. }
  30. fclose($fp);
  31. echo "Done\n";