MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / do_rounds

Function do_rounds

example_code/item_112.py:66–77  ·  view source on GitHub ↗
(database, species, *, now_func=datetime.now)

Source from the content-addressed store, hash-verified

64from datetime import datetime
65
66def do_rounds(database, species, *, now_func=datetime.now):
67 now = now_func()
68 feeding_timedelta = database.get_food_period(species)
69 animals = database.get_animals(species)
70 fed = 0
71
72 for name, last_mealtime in animals:
73 if (now - last_mealtime) >= feeding_timedelta:
74 database.feed_animal(name, now)
75 fed += 1
76
77 return fed
78
79
80print("Example 3")

Callers 2

item_112.pyFile · 0.70
mainFunction · 0.70

Calls 3

get_food_periodMethod · 0.80
get_animalsMethod · 0.80
feed_animalMethod · 0.80

Tested by

no test coverage detected