40 lines
949 B
Python
40 lines
949 B
Python
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()
|