diff --git a/01.jpg b/01.jpg new file mode 100644 index 0000000..dc981f6 Binary files /dev/null and b/01.jpg differ diff --git a/02.jpg b/02.jpg new file mode 100644 index 0000000..d20dfe7 Binary files /dev/null and b/02.jpg differ diff --git a/03.jpg b/03.jpg new file mode 100644 index 0000000..dc981f6 Binary files /dev/null and b/03.jpg differ diff --git a/04.jpg b/04.jpg new file mode 100644 index 0000000..cf9bbc3 Binary files /dev/null and b/04.jpg differ diff --git a/4_2.py b/4_2.py new file mode 100644 index 0000000..34cc3d4 --- /dev/null +++ b/4_2.py @@ -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(''): + if el[:3] == val.upper(): + return float(el.split('')[-1][:7].replace(',', '.')) + + +print(f'Курс USD = {currency_rates("USD")}') +print(f'Курс gbp = {currency_rates("gbp")}') +print(f'Курс aaa = {currency_rates("aaa")}') \ No newline at end of file diff --git a/4_4.py b/4_4.py new file mode 100644 index 0000000..2c63143 --- /dev/null +++ b/4_4.py @@ -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")}') diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..ab68168 --- /dev/null +++ b/utils.py @@ -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(''): + if el[:3] == val.upper(): + return float(el.split('')[-1][:7].replace(',', '.')) + + +if __name__ == '__main__': + print("I'm utils.py") +else: + print("I'm a module") + + +currency_rates('usd') \ No newline at end of file