Skip to content

Commit 56ba5f5

Browse files
committed
chore: uv init and some style fix
1 parent b9e8288 commit 56ba5f5

File tree

6 files changed

+384
-7
lines changed

6 files changed

+384
-7
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
port = os.getenv("PORT", 8999)
77

8-
uvicorn.run("src.api:app", host="0.0.0.0", port=port)
8+
uvicorn.run("src.api:app", host="0.0.0.0", port=int(port))

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "campuxutility"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.11"
7+
dependencies = [
8+
"fastapi>=0.116.1",
9+
"jinja2>=3.1.6",
10+
"playwright>=1.54.0",
11+
"uvicorn>=0.35.0",
12+
]

src/render.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import logging
2-
import os
3-
import time
42

53
from .util import generate_data_path
6-
from pathlib import Path
74
from playwright.async_api import async_playwright
85
from jinja2 import Template
96
from typing_extensions import TypedDict
@@ -54,11 +51,11 @@ def __init__(self):
5451
self.browser = None
5552
self.context = None
5653

57-
async def from_jinja_template(self, template: str, data: dict) -> str:
54+
async def from_jinja_template(self, template: str, data: dict) -> tuple[str, str]:
5855
html = Template(template).render(data)
5956
return await self.from_html(html)
6057

61-
async def from_html(self, html: str) -> str:
58+
async def from_html(self, html: str) -> tuple[str, str]:
6259
html_file_path, abs_path = generate_data_path(
6360
suffix="html", namespace="rendered"
6461
)

src/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import uuid
44

55

6-
def generate_data_path(suffix: str = "html", namespace: str = "default") -> str:
6+
def generate_data_path(suffix: str = "html", namespace: str = "default") -> tuple[str, str]:
77
os.makedirs("data", exist_ok=True)
88
# 同时返回相对和绝对路径
99
filename = f"{namespace}_{int(time.time())}_{uuid.uuid4().hex[:8]}.{suffix}"

0 commit comments

Comments
 (0)