Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convert(amount, cur_from, cur_to, date, requests):
- response = requests.get('https://www.cbr.ru/scripts/XML_daily.asp?date_req=' + date) # Использовать переданный requests
- soup = BeautifulSoup(response.content, 'xml')
- value1 = Decimal(".".join(soup.find('CharCode', text=cur_to).find_next_sibling('Value').string.split(',')))
- nominal = soup.find('CharCode', text=cur_to).find_next_sibling('Nominal').string
- if cur_from != 'RUR':
- value2 =Decimal(".".join(soup.find('CharCode', text=cur_from).find_next_sibling('Value').string.split(',')))
- nomina2 = soup.find('CharCode', text=cur_from).find_next_sibling('Nominal').string
- rus = (Decimal(str(value2))/Decimal(str(nomina2)))
- else:
- rus = 1
- result = Decimal(str((rus/(value1/100))*amount))
- return result.quantize(Decimal('1.0000'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement