File size: 1,132 Bytes
360c090
79743a3
5c239ba
79743a3
47ab990
 
9fbb486
79743a3
 
5c239ba
27660a3
5c239ba
47ab990
5c239ba
79743a3
3750ff9
2d467fb
3750ff9
24eb369
c6fcf99
79743a3
47ab990
c6fcf99
5c239ba
79743a3
4ddace2
2d467fb
 
4ddace2
d8e32e1
2d467fb
9fbb486
79743a3
4c519fd
79743a3
 
 
5c239ba
 
 
2d467fb
360c090
2ef32c5
5c239ba
 
2d467fb
360c090
79743a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import Dict, List, Union
from time import gmtime, strftime

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse

from modules.details import Details, rand_details
from modules.dataset import get_image, get_stats

app = FastAPI(docs_url=None, redoc_url=None)

app.mount("/static", StaticFiles(directory="static"), name="static")

card_logs = []



@app.head('/')
@app.get('/')
def index() -> FileResponse:
    return FileResponse(path="static/index.html", media_type="text/html")


@app.get('/new_card')
def new_card(pull: int, saved: int) -> Dict[str, Union[Details, str]]:
    card_logs.append({
        "pull": pull,
        "saved": saved,
        "timestamp": strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())
    })

    details: Details = rand_details()

    return {
        "details": details,
        "image": get_image(details["energy_type"]),
    }


@app.get('/stats.json')
def stats() -> Dict[str, Union[int, object]]:
    return {**get_stats(), **{"cards_served": len(card_logs)}}


@app.get('/logs.json')
def logs() -> List[str]:
    return card_logs