Skip to content

Commit

Permalink
Fix: Switch to restcountries v3 API and use common country name
Browse files Browse the repository at this point in the history
  • Loading branch information
sameh-farouk committed Feb 20, 2024
1 parent efe065d commit 432823d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scripts/init-countries.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ async function main () {
try {
const countryPromises = countries.data.map((country, index) => {
const text = 'INSERT INTO country(id, country_id, name, code, region, subregion, lat, long) VALUES($1, $2, $3, $4, $5, $6, $7, $8)'
let code = country.alpha2Code
let code = country.cca2
if (!code) {
code = country.alpha3Code
code = country.cca3
}

let lat, long = ''
Expand All @@ -62,8 +62,8 @@ async function main () {

const region = country.region || "unknown region"
const subregion = country.subregion || "unknown subregion"

return client.query(text, [index, index, country.name, code, region, subregion, lat, long])
let name = country.name["common"]
return client.query(text, [index, index, name, code, region, subregion, lat, long])
})

await Promise.all(countryPromises)
Expand Down Expand Up @@ -112,7 +112,7 @@ async function main () {
}

async function getCountries () {
return axios.get('https://restcountries.com/v2/all')
return axios.get('https://restcountries.com/v3/all')
}

async function getCities () {
Expand Down

0 comments on commit 432823d

Please sign in to comment.