commit 359f5cdeaa0109cc7627166b2c5dc90de108e0ad Author: Korolek37 Date: Sat Aug 10 19:52:48 2024 +0300 Добавить 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"]}"} +