MCP-clock / app.py
matsuap's picture
Update get_current_datetime function to return date and time in JST format
d010c20
"""
Gradioを使って現在日時と曜日を返すシンプルなWebアプリ。
ボタンを押すと現在の日時と曜日が表示されます。
"""
import gradio as gr
from datetime import datetime, timedelta, timezone
# 現在日時と曜日を返す関数
def get_current_datetime() -> str:
"""
現在の日時と曜日をJST(日本標準時)で「YYYY-MM-DD HH:MM:SS (曜日)」形式の文字列で返す。
Returns:
str: 現在の日時と曜日(例: '2024-06-01 12:34:56 (土)')
"""
jst = timezone(timedelta(hours=9))
now = datetime.now(jst)
weekdays = ['月', '火', '水', '木', '金', '土', '日']
weekday = weekdays[now.weekday()]
return now.strftime(f'%Y-%m-%d %H:%M:%S ({weekday})')
with gr.Blocks() as demo:
gr.Markdown("# 現在日時を取得するアプリ")
output = gr.Textbox(label="現在日時")
btn = gr.Button("現在日時を取得")
btn.click(get_current_datetime, outputs=output)
demo.launch(mcp_server=True)