~reviewer/hello-hut

ref: 05b11e83d429b8dc796116a590ac2d3865b314d0 hello-hut/src/hello_hut/greetings.py -rw-r--r-- 657 bytes
05b11e83 — Ines Moreau Add bash and zsh completions 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Greeting construction: pure functions with no I/O, easy to test."""

import datetime

DEFAULT_NAME = "friend"


def time_of_day_greeting(now=None):
    """Return a salutation that matches the local time of day."""
    hour = (now or datetime.datetime.now()).hour
    if 5 <= hour < 12:
        return "Good morning"
    if 12 <= hour < 18:
        return "Good afternoon"
    return "Good evening"


def greet(name=DEFAULT_NAME, shout=False, salutation=None):
    """Build a greeting such as "Hello, Ada!"."""
    if salutation is None:
        salutation = "Hello"
    message = f"{salutation}, {name}!"
    return message.upper() if shout else message