wip
This commit is contained in:
parent
d847a02781
commit
421c6a17ff
5 changed files with 133 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -962,3 +962,4 @@ FodyWeavers.xsd
|
||||||
# Additional files built by Visual Studio
|
# Additional files built by Visual Studio
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode
|
# End of https://www.toptal.com/developers/gitignore/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode
|
||||||
|
database.db
|
||||||
|
|
|
||||||
1
fastapi_timezone/__about__.py
Normal file
1
fastapi_timezone/__about__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
__version__='0.0.1'
|
||||||
27
fastapi_timezone/models.py
Normal file
27
fastapi_timezone/models.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
from datetime import datetime
|
||||||
|
from sqlmodel import Field, Session, SQLModel, create_engine
|
||||||
|
|
||||||
|
|
||||||
|
class Message(SQLModel, table=True):
|
||||||
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
|
author: str
|
||||||
|
message: str
|
||||||
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
with Session(engine) as session:
|
||||||
|
session.add(self)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get(cls, id: int):
|
||||||
|
with Session(engine) as session:
|
||||||
|
return session.get(cls, id)
|
||||||
|
|
||||||
|
sqlite_file_name = "database.db"
|
||||||
|
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||||
|
|
||||||
|
engine = create_engine(sqlite_url, echo=True)
|
||||||
|
|
||||||
|
SQLModel.metadata.create_all(engine)
|
||||||
|
|
||||||
|
|
@ -1,16 +1,62 @@
|
||||||
[project]
|
[project]
|
||||||
name = "fastapi-timezone"
|
name = "fastapi-timezone"
|
||||||
version = "0.1.1"
|
dynamic = ["version"]
|
||||||
description = "Add your description here"
|
description = 'A demo fastapi application that automatically responds with the users localized timezone.'
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.8"
|
||||||
|
license = "MIT"
|
||||||
|
keywords = []
|
||||||
|
authors = [
|
||||||
|
{ name = "Waylon Walker", email = "waylon@waylonwalker.com" },
|
||||||
|
]
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 4 - Beta",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastapi>=0.115.0",
|
"fastapi>=0.115.0",
|
||||||
"jinja2>=3.1.4",
|
"rich>=13.9.2",
|
||||||
"sqlmodel>=0.0.22",
|
|
||||||
"uvicorn>=0.31.1",
|
"uvicorn>=0.31.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[project.urls]
|
||||||
include = ["fastapi_timezone"]
|
Documentation = "https://github.com/U.N. Owen/fastapi-dynamic-response#readme"
|
||||||
exclude = ["templates", "node_modules"]
|
Issues = "https://github.com/U.N. Owen/fastapi-dynamic-response/issues"
|
||||||
|
Source = "https://github.com/U.N. Owen/fastapi-dynamic-response"
|
||||||
|
|
||||||
|
[tool.hatch.version]
|
||||||
|
path = "fastapi_timezone/__about__.py"
|
||||||
|
|
||||||
|
[tool.hatch.envs.types]
|
||||||
|
extra-dependencies = [
|
||||||
|
"mypy>=1.0.0",
|
||||||
|
]
|
||||||
|
[tool.hatch.envs.types.scripts]
|
||||||
|
check = "mypy --install-types --non-interactive {args:src/fastapi_dynamic_response tests}"
|
||||||
|
|
||||||
|
[tool.coverage.run]
|
||||||
|
source_pkgs = ["fastapi_dynamic_response", "tests"]
|
||||||
|
branch = true
|
||||||
|
parallel = true
|
||||||
|
omit = [
|
||||||
|
"src/fastapi_dynamic_response/__about__.py",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.coverage.paths]
|
||||||
|
fastapi_dynamic_response = ["src/fastapi_dynamic_response", "*/fastapi-dynamic-response/src/fastapi_dynamic_response"]
|
||||||
|
tests = ["tests", "*/fastapi-dynamic-response/tests"]
|
||||||
|
|
||||||
|
[tool.coverage.report]
|
||||||
|
exclude_lines = [
|
||||||
|
"no cov",
|
||||||
|
"if __name__ == .__main__.:",
|
||||||
|
"if TYPE_CHECKING:",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
|
||||||
50
tui.py
Normal file
50
tui.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
from textual.app import App
|
||||||
|
from textual.containers import Vertical
|
||||||
|
from textual.reactive import Reactive
|
||||||
|
from textual.widgets import Footer, Input, Static
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
# class MessageFeed(ScrollView):
|
||||||
|
# """A scrollable widget to display chat messages."""
|
||||||
|
|
||||||
|
# def __init__(self):
|
||||||
|
# super().__init__()
|
||||||
|
# self.messages = Vertical()
|
||||||
|
# self.set_content(self.messages)
|
||||||
|
|
||||||
|
# def add_message(self, sender: str, text: str):
|
||||||
|
# """Add a message to the feed."""
|
||||||
|
# timestamp = datetime.now().strftime('%H:%M:%S')
|
||||||
|
# message = Static(f"[{timestamp}] {sender}: {text}")
|
||||||
|
# self.messages.mount(message)
|
||||||
|
# self.scroll_end(animate=False)
|
||||||
|
|
||||||
|
class ChatApp(App):
|
||||||
|
"""A simple chat application using Textual."""
|
||||||
|
|
||||||
|
CSS_PATH = "chat.css"
|
||||||
|
message_input: Reactive[str] = Reactive("")
|
||||||
|
|
||||||
|
def compose(self):
|
||||||
|
"""Compose the layout of the chat app."""
|
||||||
|
# self.message_feed = MessageFeed()
|
||||||
|
self.input_box = Input(placeholder="Type your message...", id="input")
|
||||||
|
self.footer = Footer()
|
||||||
|
# yield self.message_feed
|
||||||
|
yield self.input_box
|
||||||
|
yield self.footer
|
||||||
|
|
||||||
|
async def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||||
|
"""Handle the input submission to send a message."""
|
||||||
|
if event.value.strip():
|
||||||
|
# self.message_feed.add_message("You", event.value.strip())
|
||||||
|
event.input.value = "" # Clear input after sending
|
||||||
|
|
||||||
|
def on_key(self, event):
|
||||||
|
"""Handle key events for focus and usability."""
|
||||||
|
if event.key == "escape":
|
||||||
|
self.input_box.focus()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ChatApp.run()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue