Добавить main.py
This commit is contained in:
commit
359f5cdeaa
30
main.py
Normal file
30
main.py
Normal file
|
@ -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"]}"}
|
||||
|
Loading…
Reference in New Issue
Block a user