From 1698c85bd66572e05e6a05dcd32d791530d128bd Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Tue, 7 Jan 2025 15:25:59 +0000 Subject: [PATCH] Base of parser (currency part) --- .gitignore | 2 +- parser/currency.py | 20 ++++++++++++++++++++ parser/requirements.txt | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 parser/currency.py create mode 100644 parser/requirements.txt diff --git a/.gitignore b/.gitignore index 2206544d..02932dce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ - +.venv .codegpt \ No newline at end of file diff --git a/parser/currency.py b/parser/currency.py new file mode 100644 index 00000000..01354f96 --- /dev/null +++ b/parser/currency.py @@ -0,0 +1,20 @@ +import requests +import json + +url = "https://www.cbr-xml-daily.ru/daily_json.js" + +class Currency: + def __init__(self, code: str): + self.name = code + self.status = True + response = requests.get(url) + response.raise_for_status() # Проверяем успешность запроса + try: + # Парсим JSON-данные + data = response.json() + self.yen_rate = data["Valute"][code]["Value"] + self.yen_nominal = data["Valute"][code]["Nominal"] + except: + self.status = False + +obj = Currency("JPY") \ No newline at end of file diff --git a/parser/requirements.txt b/parser/requirements.txt new file mode 100644 index 00000000..d25f1dae --- /dev/null +++ b/parser/requirements.txt @@ -0,0 +1,3 @@ +bs4==0.0.2 +requests==2.32.3 +