v3.accords-library.com/scripts/download-currencies.ts

31 lines
868 B
TypeScript
Raw Normal View History

2024-02-24 17:42:52 +00:00
import { writeFileSync } from "fs";
const OPEN_EXCHANGE_FOLDER = `${process.cwd()}/src/shared/openExchange`;
const ratesUrl = `https://openexchangerates.org/api/latest.json?app_id=${
import.meta.env.OER_APP_ID
}`;
const currenciesUrl = `https://openexchangerates.org/api/currencies.json?app_id=${
import.meta.env.OER_APP_ID
}`;
const rates = await fetch(ratesUrl);
if (rates.ok) {
writeFileSync(`${OPEN_EXCHANGE_FOLDER}/rates.json`, await rates.text(), {
encoding: "utf-8",
});
} else {
console.error("Failed to get the rates", rates.status, rates.statusText);
}
const currencies = await fetch(currenciesUrl);
if (currencies.ok) {
2024-03-02 19:35:36 +00:00
writeFileSync(`${OPEN_EXCHANGE_FOLDER}/currencies.json`, await currencies.text(), {
encoding: "utf-8",
});
2024-02-24 17:42:52 +00:00
} else {
2024-03-02 19:35:36 +00:00
console.error("Failed to get the currencies", currencies.status, currencies.statusText);
2024-02-24 17:42:52 +00:00
}