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,11 @@
# Rank tracker (Python)
Checks where a target domain ranks for a list of keywords and writes the results
to `rankings.csv`. Handles `www.` and subdomains when matching the domain.
```bash
pip install -r requirements.txt
python main.py
```
Edit `target_domain` and `keywords` in [main.py](main.py) to track your own site.

View File

@@ -0,0 +1,38 @@
import csv
from openserp import OpenSERP
target_domain = "go.dev"
keywords = ["golang tutorial", "go programming language", "golang documentation"]
output_file = "rankings.csv"
def matches(domain: str | None, target: str) -> bool:
if not domain:
return False
domain = domain.lower().removeprefix("www.")
return domain == target or domain.endswith(f".{target}")
# 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=20)
hit = next((r for r in response.results if matches(r.domain, target_domain)), None)
rows.append(
{
"keyword": keyword,
"rank": hit.rank if hit else "not in top 20",
"url": hit.url if hit else "",
}
)
print(f'"{keyword}": {rows[-1]["rank"]}')
with open(output_file, "w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=["keyword", "rank", "url"])
writer.writeheader()
writer.writerows(rows)
print(f"\nSaved rankings for {target_domain} to {output_file}")

View File

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