mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-11-24 01:26:22 +03:00
Добавлен новый роут, теперь можно получить сегодняшние обои
This commit is contained in:
parent
752914349a
commit
cc8e0333f9
1 changed files with 20 additions and 6 deletions
|
@ -1,20 +1,34 @@
|
|||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import HTMLResponse, FileResponse
|
||||
from fastapi.responses import HTMLResponse, FileResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
template = Jinja2Templates(directory='./src/web/html')
|
||||
|
||||
def get_wallpaper(date: str):
|
||||
return requests.get('https://api.nasa.gov/planetary/apod', params={
|
||||
'api_key': '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et',
|
||||
'date': date,
|
||||
})
|
||||
|
||||
@router.get('/wallpaper/today', response_class=HTMLResponse)
|
||||
async def today_wallpaper(requests: Request):
|
||||
date = datetime.today().strftime('%Y-%m-%d')
|
||||
res = get_wallpaper(date)
|
||||
|
||||
if res.status_code != 200:
|
||||
return FileResponse('./src/web/html/error/404.html')
|
||||
|
||||
return RedirectResponse(f'/wallpaper/{date}')
|
||||
|
||||
|
||||
@router.get('/wallpaper/{day}', response_class=HTMLResponse)
|
||||
async def wallpaper(request: Request, day):
|
||||
res = requests.get('https://api.nasa.gov/planetary/apod', params={
|
||||
'api_key': '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et',
|
||||
'date': day,
|
||||
})
|
||||
res = get_wallpaper(day)
|
||||
|
||||
if res.status_code != 200:
|
||||
return FileResponse('./src/web/html/error/404.html')
|
||||
|
|
Loading…
Add table
Reference in a new issue