Add OpenSERP SDK usage examples

This commit is contained in:
Rustem Kamalov
2026-06-09 04:14:35 +03:00
parent 11d02731b6
commit ffd3d4250c
35 changed files with 627 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
# Keyword list to CSV (Python)
Searches a list of keywords and writes every result to `keywords.csv`.
```bash
pip install -r requirements.txt
python main.py
```
Edit the `keywords` list in [main.py](main.py) to export your own.

View File

@@ -0,0 +1,31 @@
import csv
from openserp import OpenSERP
keywords = ["search api", "open source serp"]
output_file = "keywords.csv"
# Hosted API instead? Get a key at https://openserp.org/dashboard/keys:
#with OpenSERP(api_key="<YOUR_API_TOKEN>") as client:
with OpenSERP(base_url="http://localhost:7000") as client:
rows = []
for keyword in keywords:
response = client.search(engine="google", text=keyword, region="US", limit=10)
for result in response.results:
rows.append(
{
"keyword": keyword,
"rank": result.rank,
"title": result.title,
"url": result.url,
"domain": result.domain,
}
)
with open(output_file, "w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=["keyword", "rank", "title", "url", "domain"])
writer.writeheader()
writer.writerows(rows)
print(f"Wrote {len(rows)} rows to {output_file}")

View File

@@ -0,0 +1 @@
openserp>=0.2.0,<1