Advertisement
Roman_Sarnov

Untitled

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