From 359f5cdeaa0109cc7627166b2c5dc90de108e0ad Mon Sep 17 00:00:00 2001 From: Korolek37 Date: Sat, 10 Aug 2024 19:52:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20main.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..92a74a4 --- /dev/null +++ b/main.py @@ -0,0 +1,30 @@ +import requests as http +from fastapi import FastAPI +from datetime import datetime + + +current_year = datetime.now().current_year +current_month = datetime.now().current_month +#Так как current_month может иметь значение 8 вместо 08, идет проверка на количество разрядов +if(int(current_month) < 10): + current_month = "0" + str(current_month) +current_day = datetime.now().current_day + +#склеить строку +date = (f"{current_year}-{current_month}-{current_day}") + + +apiVersion = "v1" +endpoint = "currencies/usd.json" +url = f"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{date}/{apiVersion}/{endpoint}"; +response = http.get(url).json() +print(response["usd"]["rub"]) + + +app = FastAPI() + + +@app.get("/") +async def root(): + return {"usd": f"{response["usd"]["rub"]}"} +