Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #99

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 42 additions & 44 deletions melli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@


@app.get("/task1/greet/{name}", tags=["Task 1"], summary="👋🇩🇪🇬🇧🇪🇸")
async def task1_greet(name: str) -> str:
async def task1_greet(name: str, language: str = "de") -> str:
"""Greet somebody in German, English or Spanish!"""
# Write your code below
...
return f"Hello {name}, I am Melli."
supported_languages = ["de", "en", "es"]

if language not in supported_languages:
return "Sorry, we don't speak that language."

greetings = {
"de": f"Hallo {name}, ich bin Melli.",
"en": f"Hello {name}, I am Melli.",
"es": f"Hola {name}, soy Melli.",
}

return greetings[language]

"""
Task 2 - snake_case to cameCase
Expand All @@ -28,16 +36,16 @@ async def task1_greet(name: str) -> str:

def camelize(key: str):
"""Takes string in snake_case format returns camelCase formatted version."""
# Write your code below
...
words = key.split('_')
key = words[0] + ''.join(word.capitalize() for word in words[1:])
return key


@app.post("/task2/camelize", tags=["Task 2"], summary="🐍➡️🐪")
async def task2_camelize(data: dict[str, Any]) -> dict[str, Any]:
"""Takes a JSON object and transfroms all keys from snake_case to camelCase."""
return {camelize(key): value for key, value in data.items()}

"""Takes a JSON object and transforms all keys from snake_case to camelCase."""
camelized_data = {camelize(key): value for key, value in data.items()}
return camelized_data

"""
Task 3 - Handle User Actions
Expand All @@ -60,49 +68,39 @@ class ActionResponse(BaseModel):
message: str


def handle_call_action(action: str):
# Write your code below
...
return "🤙 Why don't you call them yourself!"


def handle_reminder_action(action: str):
# Write your code below
...
return "🔔 I can't even remember my own stuff!"

# Action handlers
def handle_call_action(username: str, action:str):
if action.split()[-1][:-1] not in friends[username]:
return "{username}, I can't find this person in your contacts."
return f"🤙 Calling {username} ..."

def handle_timer_action(action: str):
# Write your code below
...
return "⏰ I don't know how to read the clock!"
def handle_reminder_action(username: str, action:str):
return f"🔔 Alright, I will remind you!"

def handle_timer_action(username: str, action:str):
return f"⏰ Alright, the timer is set!"

def handle_unknown_action(action: str):
# Write your code below
...
return "🤬 #$!@"
def handle_unknown_action():
return "👀 Sorry , but I can't help with that!"


@app.post("/task3/action", tags=["Task 3"], summary="🤌")
def task3_action(request: ActionRequest):
"""Accepts an action request, recognizes its intent and forwards it to the corresponding action handler."""
# tip: you have to use the response model above and also might change the signature
# of the action handlers
# Write your code below
...
from random import choice

# There must be a better way!
handler = choice(
[
handle_call_action,
handle_reminder_action,
handle_timer_action,
handle_unknown_action,
]
)
return handler(request.action)
users = []
users.append(friends.keys())
if username not in users:
return f"Hi {username}, I don't know you yet. But I would love to meet you!"

action = request.action.lower()
if "call" in action.lower():
return handle_call_action(request.username, request.action)
elif "remind" in action.lower():
return handle_reminder_action(request.username, request.action)
elif "timer" in action.lower():
return handle_timer_action(request.username, request.action)
else:
return handle_unknown_action()


"""
Expand Down
Loading