31 lines
842 B
Python
31 lines
842 B
Python
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"]}"}
|
|
|