Use dominate
This commit is contained in:
parent
08fe7c1cf7
commit
1c81d6fcd4
3 changed files with 56 additions and 46 deletions
73
cry/web.py
73
cry/web.py
|
|
@ -1,8 +1,8 @@
|
|||
import asyncio
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import dominate.tags as d
|
||||
import functools
|
||||
import html
|
||||
import http.server
|
||||
import io
|
||||
import pathlib
|
||||
|
|
@ -497,48 +497,37 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||
|
||||
feeds.sort(key=feed.sort_key, reverse=True)
|
||||
|
||||
buffer = io.StringIO()
|
||||
buffer.write(
|
||||
"""
|
||||
<!doctype html>
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>Subscribed Feeds</title>
|
||||
<link rel="stylesheet" href="/style.css" type="text/css" />
|
||||
</head>
|
||||
<h1>Feeds</h1>
|
||||
<div>
|
||||
<form method="post" action="/refresh">
|
||||
<input type="submit" value="Refresh" />
|
||||
</form>
|
||||
<form method="post" action="/subscribe">
|
||||
<label for="url">Feed url: </label>
|
||||
<input type="url" name="url" />
|
||||
<input type="submit" value="Subscribe" />
|
||||
</form>
|
||||
</div>
|
||||
"""
|
||||
)
|
||||
for f in feeds:
|
||||
feed_title = html.escape(f.title)
|
||||
buffer.write(f"<div class='feed'>")
|
||||
buffer.write(
|
||||
f'<h2><a href="{f.link}" target="_blank">{feed_title}</a></h2>'
|
||||
)
|
||||
if len(f.entries) > 0:
|
||||
buffer.write(f"<ul>")
|
||||
for entry in f.entries:
|
||||
title = html.escape(entry.title)
|
||||
buffer.write(
|
||||
f'<li class="entry"><a href="{entry.link}" target="_blank">{title}</a> ({entry.time_ago()})</li>'
|
||||
)
|
||||
buffer.write(f"</ul>")
|
||||
else:
|
||||
buffer.write("<i>No entries...</i>")
|
||||
buffer.write(f"</div>") # feed
|
||||
buffer.flush()
|
||||
document = d.html()
|
||||
with document:
|
||||
with d.head():
|
||||
d.meta(charset="utf8")
|
||||
d.title("Subscribed Feeds")
|
||||
d.link(rel="stylesheet", href="/style.css", type="text/css")
|
||||
d.h1("Feeds")
|
||||
with d.div():
|
||||
with d.form(method="post", action="/refresh"):
|
||||
d.input_(type="submit", value="Refresh")
|
||||
with d.form(method="post", action="/subscribe"):
|
||||
d.label("Feed url:", fr="url")
|
||||
d.input_(type="url", name="url")
|
||||
d.input_(type="submit", value="Subscribe")
|
||||
|
||||
self.write_html(buffer.getvalue())
|
||||
for f in feeds:
|
||||
with d.div(cls="feed"):
|
||||
d.h2(d.a(f.title, href=f.link, target="_blank"))
|
||||
if len(f.entries) > 0:
|
||||
d.ul(
|
||||
d.li(
|
||||
d.a(entry.title, href=entry.link, target="_blank"),
|
||||
f" ({entry.time_ago()})",
|
||||
cls="entry",
|
||||
)
|
||||
for entry in f.entries
|
||||
)
|
||||
else:
|
||||
d.i("No entries...")
|
||||
|
||||
self.write_html(document.render())
|
||||
|
||||
def serve_subscribe_choose(self):
|
||||
try:
|
||||
|
|
|
|||
23
pdm.lock
generated
23
pdm.lock
generated
|
|
@ -3,9 +3,12 @@
|
|||
|
||||
[metadata]
|
||||
groups = ["default", "test"]
|
||||
strategy = ["cross_platform", "inherit_metadata"]
|
||||
lock_version = "4.4.2"
|
||||
content_hash = "sha256:0bb8351861012d463ce318bf45ed26567c8e4e69b76fbda2a01ffa9492d77653"
|
||||
strategy = ["inherit_metadata"]
|
||||
lock_version = "4.5.0"
|
||||
content_hash = "sha256:600f614700867fb12dfa95f2cd65b2339a6b17aaaede34b3adf9770e8f5d8011"
|
||||
|
||||
[[metadata.targets]]
|
||||
requires_python = "==3.12.*"
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
|
|
@ -52,6 +55,7 @@ summary = "Composable command line interface toolkit"
|
|||
groups = ["default"]
|
||||
dependencies = [
|
||||
"colorama; platform_system == \"Windows\"",
|
||||
"importlib-metadata; python_version < \"3.8\"",
|
||||
]
|
||||
files = [
|
||||
{file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"},
|
||||
|
|
@ -70,6 +74,17 @@ files = [
|
|||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dominate"
|
||||
version = "2.9.1"
|
||||
requires_python = ">=3.4"
|
||||
summary = "Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API."
|
||||
groups = ["default"]
|
||||
files = [
|
||||
{file = "dominate-2.9.1-py2.py3-none-any.whl", hash = "sha256:cb7b6b79d33b15ae0a6e87856b984879927c7c2ebb29522df4c75b28ffd9b989"},
|
||||
{file = "dominate-2.9.1.tar.gz", hash = "sha256:558284687d9b8aae1904e3d6051ad132dd4a8c0cf551b37ea4e7e42a31d19dc4"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "feedparser"
|
||||
version = "6.0.11"
|
||||
|
|
@ -147,9 +162,11 @@ summary = "pytest: simple powerful testing with Python"
|
|||
groups = ["test"]
|
||||
dependencies = [
|
||||
"colorama; sys_platform == \"win32\"",
|
||||
"exceptiongroup>=1.0.0rc8; python_version < \"3.11\"",
|
||||
"iniconfig",
|
||||
"packaging",
|
||||
"pluggy<2.0,>=1.5",
|
||||
"tomli>=1; python_version < \"3.11\"",
|
||||
]
|
||||
files = [
|
||||
{file = "pytest-8.2.2-py3-none-any.whl", hash = "sha256:c434598117762e2bd304e526244f67bf66bbd7b5d6cf22138be51ff661980343"},
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ dependencies = [
|
|||
"platformdirs>=4.2.2",
|
||||
"requests>=2.32.3",
|
||||
"click>=8.1.7",
|
||||
"dominate>=2.9.1",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
|
|
@ -26,7 +27,10 @@ Changelog = "https://github.com/decarabas/cry/releases"
|
|||
Issues = "https://github.com/decarabas/cry/issues"
|
||||
CI = "https://github.com/decarabas/cry/actions"
|
||||
|
||||
[project.entry-points.console_scripts]
|
||||
[project.scripts]
|
||||
cry = "cry.cli:cli"
|
||||
|
||||
[project.entry_points.console_scripts]
|
||||
cry = "cry.cli:cli"
|
||||
|
||||
[project.optional-dependencies]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue