From 9e841014de8f36dc284853190946096a1d05778d Mon Sep 17 00:00:00 2001 From: Sergey Karmanov Date: Wed, 19 Oct 2022 01:33:16 +0300 Subject: [PATCH] Update for new design --- main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 424e5b1..0da5b07 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ if (site.status_code != 200): soup = BeautifulSoup(site.text, "html.parser") -for tag in soup.find_all("span", class_="product-price-current"): +for tag in soup.find_all("div", class_="snow-price_SnowPrice__mainS__ugww0l"): KursAli = (''.join(x for x in tag.text if (x.isdigit() or x == ','))).replace(',','.') print("Курс Ali: " + KursAli) @@ -36,6 +36,8 @@ if (site.status_code != 200): KursCBRF = str(json.loads(site.text)["Valute"]["USD"]["Value"]) print("Курс ЦБ РФ: " + KursCBRF) +print("Разница Ali и CBRF", round(max(float(KursAli), float(KursCBRF)) - min(float(KursAli), float(KursCBRF)), 2)) + # Send metrics ↓ url = MetricServerURL + 'api/v1/import/csv?format=1:label:source,2:metric:exchange_usd_rub' @@ -52,4 +54,11 @@ if KursAli != '': if (x.status_code != 200 and x.status_code != 204): print("Не удалось отправить метрику: " + str(x.status_code)) else: - print("Курс Али пуст") \ No newline at end of file + print("Курс Али пуст") + +if KursCBRF != '' and KursAli != '': + x = requests.post(url, "Diff Ali CBRF," + str(round(max(float(KursAli), float(KursCBRF)) - min(float(KursAli), float(KursCBRF)), 2))) + if (x.status_code != 200 and x.status_code != 204): + print("Не удалось отправить метрику: " + str(x.status_code)) +else: + print("Один из курсов пуст") \ No newline at end of file