The-Chef commited on
Commit
52ee136
·
verified ·
1 Parent(s): 05e2676

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -22
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
- 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
  ]
 
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
  ]