Last active
January 3, 2026 16:03
-
-
Save ergomancer/61c721e41b9a9d81306ad2224dee3c0e to your computer and use it in GitHub Desktop.
A script to fetch Purchasing Power Parity (PPP) data from the World Bank API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| v1.0.x | |
| NPM Package: npm install countrypppdata | |
| */ | |
| const axios = require("axios"); | |
| const { getCodes, getCodeList } = require("country-list"); | |
| async function fetchCountryData() { | |
| let countries = getCodes(); | |
| const countriesList = getCodeList(); | |
| let countryName, pf; | |
| const result = []; | |
| const miss = []; | |
| for (country of countries) { | |
| try { | |
| let pfRes = await axios.get( | |
| "https://api.worldbank.org/v2/country/" + | |
| country + | |
| "/indicator/pa.nus.pppc.rf?format=json" | |
| ); | |
| let pfDataset = pfRes.data[1]; | |
| for (pfData of pfDataset) { | |
| countryName = pfData["country"]["value"]; | |
| pf = pfData["value"]; | |
| if (pf != null) { | |
| break; | |
| } | |
| } | |
| pf = pf || 0.7; | |
| result.push({ country, countryName, pf }); | |
| } catch (err) { | |
| miss.push(country); | |
| } | |
| } | |
| for (code of miss) { | |
| countryName = countriesList[code.toLowerCase()]; | |
| pf = 0.7; | |
| result.push({ country, countryName, pf }); | |
| } | |
| return result; | |
| } | |
| module.exports = fetchCountryData; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for sharing!