Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 02.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 03.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 04.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions 4_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from requests import get, utils

response = get('http://www.cbr.ru/scripts/XML_daily.asp')
encodings = utils.get_encoding_from_headers(response.headers)
content = response.content.decode(encoding=encodings)


def currency_rates(val):

for el in content.split('</NumCode><CharCode>'):
if el[:3] == val.upper():
return float(el.split('</Name><Value>')[-1][:7].replace(',', '.'))


print(f'Курс USD = {currency_rates("USD")}')
print(f'Курс gbp = {currency_rates("gbp")}')
print(f'Курс aaa = {currency_rates("aaa")}')
5 changes: 5 additions & 0 deletions 4_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import utils as ut

print(f'Курс USD = {ut.currency_rates("USD")}')
print(f'Курс gbp = {ut.currency_rates("gbp")}')
print(f'Курс aaa = {ut.currency_rates("aaa")}')
21 changes: 21 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from requests import get, utils

response = get('http://www.cbr.ru/scripts/XML_daily.asp')
encodings = utils.get_encoding_from_headers(response.headers)
content = response.content.decode(encoding=encodings)


def currency_rates(val):

for el in content.split('</NumCode><CharCode>'):
if el[:3] == val.upper():
return float(el.split('</Name><Value>')[-1][:7].replace(',', '.'))


if __name__ == '__main__':
print("I'm utils.py")
else:
print("I'm a module")


currency_rates('usd')