-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
19 lines (14 loc) · 663 Bytes
/
app.py
File metadata and controls
19 lines (14 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastapi import FastAPI, HTTPException
import uvicorn
import requests
app = FastAPI()
@app.get('/')
def index():
try:
deck = requests.get("https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1").json()
response_cards = requests.get(f"https://deckofcardsapi.com/api/deck/{deck['deck_id']}/draw/?count=1").json()
return f"{response_cards['cards'][0]['value']} of {response_cards['cards'][0]['suit']}"
except requests.exceptions.RequestException as e:
raise HTTPException(status_code=500, detail="Erro ao acessar o servidor")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=5000)