Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Конвертер валют ЦБ РФ (https://javascript.ru/forum/misc/84301-konverter-valyut-cb-rf.html)

ilyamio 01.08.2022 16:08

Конвертер валют ЦБ РФ
 
Здравствуйте.
Имеется рабочий скрипт конвертера валют. https://ilyamio.github.io/currencyconverter/
Но курсы он берет с другого сервиса. А необходимо чтобы курсы брались с сайта ЦБ РФ. https://www.cbr.ru/scripts/XML_daily.asp
Важно! Необходимо установить ограничение на количество обращений к сайту ЦБ РФ - 1 раз в сутки. При частом обращении, могут заблокировать.

Все файлы конвертера тут https://github.com/ilyamio/currencyconverter

Все настройки находятся в файле function.js
https://github.com/ilyamio/currencyc...in/function.js
const from_currencyEl = document.getElementById('from_currency');
const from_ammountEl = document.getElementById('from_ammount');
const to_currencyEl = document.getElementById('to_currency');
const to_ammountEl = document.getElementById('to_ammount');
const rateEl = document.getElementById('rate');
const exchange = document.getElementById('exchange');

from_currencyEl.addEventListener('change', calculate);
from_ammountEl.addEventListener('input', calculate);
to_currencyEl.addEventListener('change', calculate);
to_ammountEl.addEventListener('input', calculate);

exchange.addEventListener('click', () => {
	const temp = from_currencyEl.value;
	from_currencyEl.value = to_currencyEl.value;
	to_currencyEl.value = temp;
	calculate();
});

function calculate() {
	const from_currency = from_currencyEl.value;
	const to_currency = to_currencyEl.value;
	
	fetch(`https://api.exchangerate-api.com/v4/latest/${from_currency}`)
		.then(res => res.json())
		.then(res => {
		const rate = res.rates[to_currency];
		rateEl.innerText = `1 ${from_currency} = ${rate} ${to_currency}`
		to_ammountEl.value = (from_ammountEl.value * rate).toFixed(2);
	})
}

calculate();


Что хочу сделать:
  1. Мне необходимо чтобы курсы валют брались из ЦБ РФ.
  2. Включить ограничение на количество обращений по ссылке cbr.ru - 1 раз в сутки. Если не ошибаюсь, это называется кэширование.

Пожалуйста, напишите, может кто-нибудь знает решение этой задаче.
Очень надеюсь, что поможете. Спасибо!

voraa 01.08.2022 19:06

В раздел "работа" попробуйте написать.
https://javascript.ru/forum/job/


Часовой пояс GMT +3, время: 04:34.