夏季刊搬运完成

This commit is contained in:
hydrogen committed 2026-04-18 17:02:12 +08:00
commit a1acb18288
31 files changed
+2777

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import click
import requests
import html2text
@click.command()
@click.argument("url")
@click.argument("id", nargs=-1)
@click.option(
"--format",
"output_format",
type=click.Choice(["markdown", "html"], case_sensitive=False),
default="markdown",
show_default=True,
help="The output format",
)
@click.option(
"--delimiter",
"delimiter",
default="\n\n",
show_default=True,
help="The delimiter to use between multiple outputs",
)
def main(url: str, id: tuple[str], output_format: str, delimiter: str) -> None:
for topic_id in id:
html = requests.get(f"{url}/t/{topic_id}.json").json()["post_stream"]["posts"][
0
]["cooked"]
match output_format:
case "markdown":
result = html2text.html2text(html)
case "html":
result = html
print(result)
print(delimiter)
if __name__ == "__main__":
main()