Add base virtue api

This commit is contained in:
Tyler Perkins 2023-07-25 23:08:50 -04:00
parent 6bc02dc4c5
commit 9412dcd577
3 changed files with 46 additions and 0 deletions

5
src/config.py Normal file
View File

@ -0,0 +1,5 @@
from envyaml import EnvYAML
import os
def getConfig():
return EnvYAML(os.getenv("CONFIG", "config.yaml"))

3
src/config.yaml Normal file
View File

@ -0,0 +1,3 @@
openapi_key: sk-
openapi_url:

38
src/main.py Normal file
View File

@ -0,0 +1,38 @@
from fastapi import FastAPI
import datetime
app = FastAPI()
ben_franklin_virtues = {
"Temperance": "Practice moderation in all things, especially eating and drinking. Don't overindulge.",
"Silence": "Speak only when it contributes to the well-being of yourself or others. Avoid unnecessary chatter.",
"Order": "Keep your personal and professional life organized. A tidy environment can lead to a tidy mind.",
"Resolution": "Be determined in your actions. If you decide to do something, follow through until it's done.",
"Frugality": "Be mindful of your spending. Save and invest wisely, and avoid unnecessary expenses.",
"Industry": "Make the most of your time. Be productive and avoid idle activities.",
"Sincerity": "Be genuine and honest in your interactions with others. Avoid deceit.",
"Justice": "Treat others fairly and justly. Don't harm others by your actions or neglect.",
"Moderation": "Avoid extremes. Be moderate in your actions and avoid holding extreme opinions.",
"Cleanliness": "Keep your body, clothes, and living spaces clean. Good hygiene and cleanliness can contribute to good health.",
"Tranquility": "Don't let minor issues upset you. Stay calm and composed, even in difficult situations.",
"Chastity": "Respect your body and the bodies of others. Engage in sexual activities responsibly and consensually.",
"Humility": "Be humble. Don't think too highly of yourself, and appreciate the value in others."
}
@app.get("/")
async def virtue():
"""
Get the virtue of the week
"""
current_week = datetime.date.today().isocalendar()[1]
virtues = list(ben_franklin_virtues.keys())
virtue_of_the_week = virtues[(current_week - 1) % 13]
return {
"virtue": virtue_of_the_week,
"content": ben_franklin_virtues[virtue_of_the_week]
}