diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fad2ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__pycache__/ +*.py[cod] +*.egg-info/ +.venv/ + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd95271 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# toy01_table_stripper + +This is a minimal Python package that demonstrates how to use the `uv` tool for +managing dependencies and running the application. + +## Development + +Create a virtual environment and install dependencies using `uv`: + +```bash +uv venv +uv pip install -e . +``` + +Run the command-line interface by piping an HTML file: + +```bash +cat sample.html | toy01-table-stripper +``` + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..78313ed --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[build-system] +requires = ["uv>=0.1.0"] +build-backend = "uv.build" + +[project] +name = "toy01_table_stripper" +version = "0.1.0" +readme = "README.md" +authors = [ + {name = "pathcosmos", email = "lanco.gh@gmail.com"} +] +dependencies = [] +requires-python = ">=3.10" + +[project.scripts] +toy01-table-stripper = "toy01_table_stripper.main:main" + diff --git a/toy01_table_stripper/__init__.py b/toy01_table_stripper/__init__.py new file mode 100644 index 0000000..6513702 --- /dev/null +++ b/toy01_table_stripper/__init__.py @@ -0,0 +1,20 @@ +"""toy01_table_stripper package.""" + +__all__ = ["strip_table"] + + +def strip_table(data: str) -> str: + """Return the input string without any HTML tags.""" + result_lines = [] + in_table = False + for line in data.splitlines(): + if "" in line: + in_table = False + continue + if not in_table: + result_lines.append(line) + return "\n".join(result_lines) + diff --git a/toy01_table_stripper/main.py b/toy01_table_stripper/main.py new file mode 100644 index 0000000..74fb9d4 --- /dev/null +++ b/toy01_table_stripper/main.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +import sys +from toy01_table_stripper import strip_table + + +def main() -> int: + data = sys.stdin.read() + print(strip_table(data)) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) +