Create app.py
Browse files
app.py
CHANGED
|
@@ -4,62 +4,83 @@ from datetime import datetime
|
|
| 4 |
|
| 5 |
app = FastAPI(title="The-Chef's Epic API", version="2.0.0")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
"Honey never spoils",
|
| 9 |
-
"Octopuses have
|
| 10 |
-
"Bananas are berries",
|
| 11 |
-
"
|
| 12 |
]
|
| 13 |
|
| 14 |
QUOTES = [
|
| 15 |
-
"
|
| 16 |
-
"Innovation distinguishes
|
| 17 |
-
"Believe
|
| 18 |
]
|
| 19 |
|
| 20 |
@app.get("/")
|
| 21 |
def home():
|
| 22 |
return {
|
| 23 |
"message": "Welcome to The-Chef's Epic API!",
|
| 24 |
-
"
|
| 25 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
@app.get("/status")
|
| 29 |
-
def
|
| 30 |
return {
|
| 31 |
"status": "ONLINE",
|
| 32 |
-
"
|
| 33 |
"version": "2.0.0",
|
| 34 |
-
"
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
@app.get("/fact")
|
| 38 |
-
def
|
| 39 |
-
return {
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
@app.get("/motivate")
|
| 42 |
-
def
|
| 43 |
-
return {
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@app.get("/time")
|
| 46 |
-
def
|
| 47 |
now = datetime.now()
|
| 48 |
return {
|
| 49 |
-
"
|
| 50 |
"date": now.strftime("%Y-%m-%d"),
|
|
|
|
| 51 |
"day": now.strftime("%A")
|
| 52 |
}
|
| 53 |
|
| 54 |
@app.get("/hello/{name}")
|
| 55 |
-
def
|
|
|
|
| 56 |
return {
|
| 57 |
-
"message": f"{
|
| 58 |
-
"
|
|
|
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
}
|
| 61 |
}
|
| 62 |
}
|
|
|
|
| 63 |
}
|
| 64 |
]
|
| 65 |
]
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI(title="The-Chef's Epic API", version="2.0.0")
|
| 6 |
|
| 7 |
+
COOL_FACTS = [
|
| 8 |
+
"Honey never spoils - 3000 year old honey is still edible",
|
| 9 |
+
"Octopuses have three hearts and blue blood",
|
| 10 |
+
"Bananas are berries but strawberries aren't",
|
| 11 |
+
"A day on Venus is longer than its year"
|
| 12 |
]
|
| 13 |
|
| 14 |
QUOTES = [
|
| 15 |
+
"The only way to do great work is to love what you do - Steve Jobs",
|
| 16 |
+
"Innovation distinguishes between a leader and a follower - Steve Jobs",
|
| 17 |
+
"Believe you can and you're halfway there - Theodore Roosevelt"
|
| 18 |
]
|
| 19 |
|
| 20 |
@app.get("/")
|
| 21 |
def home():
|
| 22 |
return {
|
| 23 |
"message": "Welcome to The-Chef's Epic API!",
|
| 24 |
+
"version": "2.0.0",
|
| 25 |
+
"endpoints": {
|
| 26 |
+
"/status": "System status and info",
|
| 27 |
+
"/fact": "Random cool fact",
|
| 28 |
+
"/motivate": "Motivational quote",
|
| 29 |
+
"/time": "Current server time",
|
| 30 |
+
"/hello/{name}": "Personal greeting",
|
| 31 |
+
"/docs": "API documentation"
|
| 32 |
+
},
|
| 33 |
+
"coolness_level": "Over 9000"
|
| 34 |
}
|
| 35 |
|
| 36 |
@app.get("/status")
|
| 37 |
+
def get_status():
|
| 38 |
return {
|
| 39 |
"status": "ONLINE",
|
| 40 |
+
"api_name": "The-Chef's Epic API",
|
| 41 |
"version": "2.0.0",
|
| 42 |
+
"message": "Running smooth",
|
| 43 |
+
"vibe": "Maximum coolness"
|
| 44 |
}
|
| 45 |
|
| 46 |
@app.get("/fact")
|
| 47 |
+
def random_fact():
|
| 48 |
+
return {
|
| 49 |
+
"fact": random.choice(COOL_FACTS),
|
| 50 |
+
"category": "Mind Blown"
|
| 51 |
+
}
|
| 52 |
|
| 53 |
@app.get("/motivate")
|
| 54 |
+
def get_motivation():
|
| 55 |
+
return {
|
| 56 |
+
"quote": random.choice(QUOTES),
|
| 57 |
+
"message": "You got this!"
|
| 58 |
+
}
|
| 59 |
|
| 60 |
@app.get("/time")
|
| 61 |
+
def get_time():
|
| 62 |
now = datetime.now()
|
| 63 |
return {
|
| 64 |
+
"current_time": now.isoformat(),
|
| 65 |
"date": now.strftime("%Y-%m-%d"),
|
| 66 |
+
"time": now.strftime("%H:%M:%S"),
|
| 67 |
"day": now.strftime("%A")
|
| 68 |
}
|
| 69 |
|
| 70 |
@app.get("/hello/{name}")
|
| 71 |
+
def greet_user(name: str):
|
| 72 |
+
greeting = random.choice(["Hey", "Hello", "Hi", "Yo", "What's up"])
|
| 73 |
return {
|
| 74 |
+
"message": f"{greeting}, {name}!",
|
| 75 |
+
"status": "You're awesome",
|
| 76 |
+
"coolness_boost": "+100"
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
}
|
| 80 |
}
|
| 81 |
}
|
| 82 |
}
|
| 83 |
+
}
|
| 84 |
}
|
| 85 |
]
|
| 86 |
]
|