Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +1,65 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import random
|
| 3 |
from datetime import datetime
|
| 4 |
-
import platform
|
| 5 |
|
| 6 |
-
app = FastAPI(
|
| 7 |
-
title="The-Chef's Epic API",
|
| 8 |
-
description="A seriously cool API with multiple endpoints",
|
| 9 |
-
version="2.0.0"
|
| 10 |
-
)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
"Honey never spoils
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"There are more stars in the universe than grains of sand on all Earth's beaches."
|
| 18 |
]
|
| 19 |
|
| 20 |
QUOTES = [
|
| 21 |
-
"
|
| 22 |
-
"Innovation distinguishes
|
| 23 |
-
"
|
| 24 |
-
"Success is not final, failure is not fatal: courage to continue counts."
|
| 25 |
]
|
| 26 |
|
| 27 |
@app.get("/")
|
| 28 |
-
def
|
| 29 |
return {
|
| 30 |
"message": "Welcome to The-Chef's Epic API!",
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"/status - Get system status",
|
| 34 |
-
"/random-fact - Get a cool fact",
|
| 35 |
-
"/motivate - Get motivated",
|
| 36 |
-
"/time - Current time",
|
| 37 |
-
"/hello/{name} - Personalized greeting",
|
| 38 |
-
"/docs - API documentation"
|
| 39 |
-
],
|
| 40 |
-
"coolness_level": "Over 9000!"
|
| 41 |
}
|
| 42 |
|
| 43 |
@app.get("/status")
|
| 44 |
-
def
|
| 45 |
return {
|
| 46 |
"status": "ONLINE",
|
| 47 |
-
"
|
| 48 |
"version": "2.0.0",
|
| 49 |
-
"
|
| 50 |
-
"python_version": platform.python_version(),
|
| 51 |
-
"message": "Running smooth like butter",
|
| 52 |
-
"coolness_level": "Maximum"
|
| 53 |
}
|
| 54 |
|
| 55 |
-
@app.get("/
|
| 56 |
-
def
|
| 57 |
-
return {
|
| 58 |
-
"fact": random.choice(COOL_FACTS),
|
| 59 |
-
"category": "Mind Blown",
|
| 60 |
-
"timestamp": datetime.now().isoformat()
|
| 61 |
-
}
|
| 62 |
|
| 63 |
@app.get("/motivate")
|
| 64 |
-
def
|
| 65 |
-
return {
|
| 66 |
-
"quote": random.choice(QUOTES),
|
| 67 |
-
"message": "You got this!",
|
| 68 |
-
"timestamp": datetime.now().isoformat()
|
| 69 |
-
}
|
| 70 |
|
| 71 |
@app.get("/time")
|
| 72 |
-
def
|
| 73 |
now = datetime.now()
|
| 74 |
return {
|
| 75 |
-
"current_time": now.isoformat(),
|
| 76 |
-
"date": now.strftime("%Y-%m-%d"),
|
| 77 |
"time": now.strftime("%H:%M:%S"),
|
|
|
|
| 78 |
"day": now.strftime("%A")
|
| 79 |
}
|
| 80 |
|
| 81 |
@app.get("/hello/{name}")
|
| 82 |
-
def
|
| 83 |
-
greeting = random.choice(["Hey", "Hello", "Hi", "Yo"])
|
| 84 |
return {
|
| 85 |
-
"message": f"{
|
| 86 |
-
"
|
| 87 |
-
|
| 88 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import random
|
| 3 |
from datetime import datetime
|
|
|
|
| 4 |
|
| 5 |
+
app = FastAPI(title="The-Chef's Epic API", version="2.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
FACTS = [
|
| 8 |
+
"Honey never spoils",
|
| 9 |
+
"Octopuses have 3 hearts",
|
| 10 |
+
"Bananas are berries",
|
| 11 |
+
"Venus days are longer than its years"
|
|
|
|
| 12 |
]
|
| 13 |
|
| 14 |
QUOTES = [
|
| 15 |
+
"Do great work - Steve Jobs",
|
| 16 |
+
"Innovation distinguishes leaders - Steve Jobs",
|
| 17 |
+
"Believe in your dreams - Eleanor Roosevelt"
|
|
|
|
| 18 |
]
|
| 19 |
|
| 20 |
@app.get("/")
|
| 21 |
+
def home():
|
| 22 |
return {
|
| 23 |
"message": "Welcome to The-Chef's Epic API!",
|
| 24 |
+
"endpoints": ["/status", "/fact", "/motivate", "/time", "/hello/{name}", "/docs"],
|
| 25 |
+
"coolness": "Maximum"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
@app.get("/status")
|
| 29 |
+
def status():
|
| 30 |
return {
|
| 31 |
"status": "ONLINE",
|
| 32 |
+
"api": "The-Chef's Epic API",
|
| 33 |
"version": "2.0.0",
|
| 34 |
+
"vibe": "Unstoppable"
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
+
@app.get("/fact")
|
| 38 |
+
def get_fact():
|
| 39 |
+
return {"fact": random.choice(FACTS), "category": "Cool"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
@app.get("/motivate")
|
| 42 |
+
def motivate():
|
| 43 |
+
return {"quote": random.choice(QUOTES), "message": "You got this!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@app.get("/time")
|
| 46 |
+
def time_now():
|
| 47 |
now = datetime.now()
|
| 48 |
return {
|
|
|
|
|
|
|
| 49 |
"time": now.strftime("%H:%M:%S"),
|
| 50 |
+
"date": now.strftime("%Y-%m-%d"),
|
| 51 |
"day": now.strftime("%A")
|
| 52 |
}
|
| 53 |
|
| 54 |
@app.get("/hello/{name}")
|
| 55 |
+
def hello(name: str):
|
|
|
|
| 56 |
return {
|
| 57 |
+
"message": f"{random.choice(['Hey', 'Hi', 'Yo'])}, {name}!",
|
| 58 |
+
"boost": "+100 points"
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
]
|
| 65 |
+
]
|