~reviewer/hello-hut

ref: v0.2.0 hello-hut/src/hello_hut/greetings.py -rw-r--r-- 657 bytes
2f5d5c0e — Dana Whitfield Release 0.2.0 a month 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