Re-license Pry from full Proprietary to a dual-license model: - Core engine, extraction, templates (80+), MCP server, x402 payment rail, CLI, SDK, browser extension, WordPress plugin, Shopify app, and llm_providers: MIT (see LICENSE) - Anti-detection / stealth subset (15 files): BSL 1.1 with Change Date 2029-01-01 (see LICENSE-BSL-STEALTH) BSL files (anti-detection moat): ultimate_scraper.py, stealth_engine.py, stealth_scripts/*.js (6), camoufox_integration.py, tls_fingerprint.py, cookie_warmer.py, behavioral_biometrics.py, adaptive.py, browser_pool.py, network.py, captcha_solver.py, shadow_dom.py, lazy_load.py, signup_automator.py, auth_connector.py This enables community contributions to the core engine (templates, integrations, MCP tools) while protecting the anti-detection techniques that constitute the actual competitive moat. BSL Additional Use Grant permits free non-production use; production deployment requires a commercial license from enterprise@rugmunch.io. Changes: - Replace proprietary LICENSE with MIT LICENSE + new LICENSE-BSL-STEALTH - Add SPDX-License-Identifier headers to 300+ source files - Add docs/adr/0002-dual-licensing.md (ADR documenting the decision) - Update README.md: new License section with BSL Additional Use Grant - Update LICENSING_PRICING_STRATEGY.md: Section 3 (PryScraper) for dual license - Update AGENTS.md: license line in header + new rule 8 (PRs touching BSL rejected) - Update pyproject.toml: license = "MIT AND BSL-1.1" + classifiers + license-files - Update DECISIONS.md index with ADR-0002 - Update STATUS.md (2026-07-03) and PLAN.md sprint goals Refs: ADR-0002
197 lines
6.5 KiB
Python
197 lines
6.5 KiB
Python
"""Pry — Commerce Platform Sync Engine.
|
|
Unified interface for WooCommerce, Shopify, and generic API sync."""
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
# Copyright (c) 2026 Rug Munch Media LLC
|
|
#
|
|
# Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper
|
|
# Licensed under MIT. See LICENSE.
|
|
|
|
import logging
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# ── Record sync operation ──
|
|
|
|
COMMERCE_DIR = Path(os.path.expanduser("~/.pry/commerce"))
|
|
COMMERCE_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
async def sync_to_woocommerce(
|
|
products: list[dict[str, Any]],
|
|
wp_url: str,
|
|
consumer_key: str,
|
|
consumer_secret: str,
|
|
category_id: int = 0,
|
|
status: str = "draft",
|
|
) -> dict[str, Any]:
|
|
"""Sync products to WooCommerce via REST API.
|
|
|
|
Args:
|
|
products: List of product dicts with name, price, description, image_url
|
|
wp_url: WordPress site URL (e.g., https://mystore.com)
|
|
consumer_key: WooCommerce REST API consumer key
|
|
consumer_secret: WooCommerce REST API consumer secret
|
|
category_id: Product category ID to assign
|
|
status: Product status (draft, publish, pending)
|
|
"""
|
|
from client import get_client
|
|
|
|
client = await get_client()
|
|
base_url = wp_url.rstrip("/")
|
|
auth = (consumer_key, consumer_secret)
|
|
|
|
results = []
|
|
for product in products:
|
|
wc_product = {
|
|
"name": product.get("name", "Unnamed Product")[:255],
|
|
"regular_price": str(product.get("price", 0)),
|
|
"description": (product.get("description") or product.get("content", ""))[:5000],
|
|
"short_description": (product.get("short_description") or "")[:500],
|
|
"images": [{"src": product["image_url"]}] if product.get("image_url") else [],
|
|
"categories": [{"id": category_id}] if category_id else [],
|
|
"status": status,
|
|
"meta_data": [
|
|
{"key": "_pry_source_url", "value": product.get("url", "")},
|
|
{
|
|
"key": "_pry_imported_at",
|
|
"value": __import__("datetime")
|
|
.datetime.now(__import__("datetime").timezone.utc)
|
|
.isoformat(),
|
|
},
|
|
],
|
|
}
|
|
|
|
try:
|
|
resp = await client.post(
|
|
f"{base_url}/wp-json/wc/v3/products",
|
|
json=wc_product,
|
|
auth=auth,
|
|
timeout=30,
|
|
)
|
|
if resp.is_success:
|
|
data = resp.json()
|
|
results.append(
|
|
{
|
|
"success": True,
|
|
"woo_id": data.get("id"),
|
|
"name": data.get("name"),
|
|
"edit_url": f"{base_url}/wp-admin/post.php?post={data.get('id')}&action=edit",
|
|
}
|
|
)
|
|
else:
|
|
results.append(
|
|
{
|
|
"success": False,
|
|
"name": product.get("name", "Unknown"),
|
|
"error": f"WooCommerce error {resp.status_code}: {resp.text[:200]}",
|
|
}
|
|
)
|
|
except Exception as e:
|
|
results.append(
|
|
{
|
|
"success": False,
|
|
"name": product.get("name", "Unknown"),
|
|
"error": str(e)[:200],
|
|
}
|
|
)
|
|
|
|
success_count = sum(1 for r in results if r["success"])
|
|
return {
|
|
"success": success_count > 0,
|
|
"total": len(products),
|
|
"synced": success_count,
|
|
"failed": len(products) - success_count,
|
|
"results": results,
|
|
}
|
|
|
|
|
|
async def sync_to_shopify(
|
|
products: list[dict[str, Any]],
|
|
shop_url: str,
|
|
access_token: str,
|
|
) -> dict[str, Any]:
|
|
"""Sync products to Shopify via REST API.
|
|
|
|
Args:
|
|
products: List of product dicts with name, price, description, image_url
|
|
shop_url: Shopify store URL (e.g., https://mystore.myshopify.com)
|
|
access_token: Shopify admin API access token
|
|
"""
|
|
from client import get_client
|
|
|
|
client = await get_client()
|
|
base_url = shop_url.rstrip("/")
|
|
|
|
results = []
|
|
for product in products:
|
|
shopify_product = {
|
|
"product": {
|
|
"title": (product.get("name") or "Unnamed Product")[:255],
|
|
"body_html": f"<div>{(product.get('description') or product.get('content', ''))[:5000]}</div>",
|
|
"vendor": "Pry Import",
|
|
"product_type": "Reference",
|
|
"status": "draft",
|
|
"variants": [
|
|
{
|
|
"price": str(product.get("price", 0)),
|
|
"inventory_management": "shopify",
|
|
}
|
|
],
|
|
"metafields": [
|
|
{
|
|
"key": "pry_source_url",
|
|
"value": product.get("url", ""),
|
|
"type": "single_line_text_field",
|
|
"namespace": "pry",
|
|
}
|
|
],
|
|
}
|
|
}
|
|
|
|
try:
|
|
resp = await client.post(
|
|
f"{base_url}/admin/api/2024-01/products.json",
|
|
json=shopify_product,
|
|
headers={"X-Shopify-Access-Token": access_token},
|
|
timeout=30,
|
|
)
|
|
if resp.is_success:
|
|
data = resp.json()
|
|
pid = data.get("product", {}).get("id")
|
|
results.append(
|
|
{
|
|
"success": True,
|
|
"shopify_id": pid,
|
|
"name": data.get("product", {}).get("title"),
|
|
"edit_url": f"{base_url}/admin/products/{pid}",
|
|
}
|
|
)
|
|
else:
|
|
results.append(
|
|
{
|
|
"success": False,
|
|
"name": product.get("name", "Unknown"),
|
|
"error": f"Shopify error {resp.status_code}: {resp.text[:200]}",
|
|
}
|
|
)
|
|
except Exception as e:
|
|
results.append(
|
|
{
|
|
"success": False,
|
|
"name": product.get("name", "Unknown"),
|
|
"error": str(e)[:200],
|
|
}
|
|
)
|
|
|
|
success_count = sum(1 for r in results if r["success"])
|
|
return {
|
|
"success": success_count > 0,
|
|
"total": len(products),
|
|
"synced": success_count,
|
|
"failed": len(products) - success_count,
|
|
"results": results,
|
|
}
|