Function fortune
from raimad.fortune
def fortune(category: str | None = None) -> str
Click to show code
def fortune(category: str | None = None) -> str:
if not category:
category = ''
category = category.lower().strip()
if not category or category in {'any', 'all'}:
return choice(fortunes_all)
if category.lower() == 'technology':
return choice(fortunes_technology)
if category.lower() == 'economy':
return choice(fortunes_economy)
if category.lower() == 'education':
return choice(fortunes_education)
if category.lower() == 'politics':
return choice(fortunes_politics)
if category.lower() == 'engineering':
return choice(fortunes_engineering)
if category.lower() == 'resilience':
return choice(fortunes_resilience)
if category.lower() == 'nonsense':
return choice(fortunes_nonsense)
if category.lower() == 'misc':
return choice(fortunes_misc)
raise ValueError(f'Unknown category `{category}`')