mirror of
https://github.com/karust/openserp.git
synced 2026-08-05 16:53:54 +08:00
Add OpenSERP SDK usage examples
This commit is contained in:
10
examples/content/python-extract-markdown/README.md
Normal file
10
examples/content/python-extract-markdown/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Extract a page to Markdown (Python)
|
||||
|
||||
Extracts one URL with `/extract` and writes the cleaned page content to `extracted.md`.
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
python main.py
|
||||
```
|
||||
|
||||
Edit the `url` in [main.py](main.py) to extract a different page.
|
||||
16
examples/content/python-extract-markdown/main.py
Normal file
16
examples/content/python-extract-markdown/main.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from openserp import OpenSERP
|
||||
|
||||
url = "https://go.dev/doc/"
|
||||
output_file = "extracted.md"
|
||||
|
||||
# Hosted API instead? Get a key at https://openserp.org/dashboard/keys:
|
||||
# with OpenSERP(api_key="<YOUR_API_TOKEN>", timeout=60.0) as client:
|
||||
with OpenSERP(base_url="http://localhost:7000", timeout=60.0) as client:
|
||||
# /extract turns a single page into clean Markdown (or plain text).
|
||||
result = client.extract(url=url, mode="auto", clean=True)
|
||||
|
||||
content = result.markdown or result.text or ""
|
||||
with open(output_file, "w", encoding="utf-8") as handle:
|
||||
handle.write(content)
|
||||
|
||||
print(f"Extracted {len(content)} characters from {url} into {output_file}")
|
||||
@@ -0,0 +1 @@
|
||||
openserp>=0.2.0,<1
|
||||
Reference in New Issue
Block a user