| 1 | const fs = require('fs'); |
| 2 | |
| 3 | async function run() { |
| 4 | const res = await fetch('https://restcountries.com/v3.1/all'); |
| 5 | const data = await res.json(); |
| 6 | |
| 7 | const map = {}; |
| 8 | for (const country of data) { |
| 9 | if (country.cca2 && country.latlng && country.latlng.length === 2) { |
| 10 | map[country.cca2] = { |
| 11 | name: country.name.common, |
| 12 | lat: country.latlng[0], |
| 13 | lng: country.latlng[1] |
| 14 | }; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fs.writeFileSync('region_map.json', JSON.stringify(map, null, 2)); |
| 19 | console.log('Done mapping ' + Object.keys(map).length + ' regions.'); |
| 20 | } |
| 21 | run(); |