diff --git a/scripts/this_script.py b/scripts/this_script.py new file mode 100644 index 00000000..0e07fa27 --- /dev/null +++ b/scripts/this_script.py @@ -0,0 +1,89 @@ +# Complete script to modify Shopify store via API key +# Usage: Replace placeholders with your credentials. Run in Cursor terminal: pip install shopify-python-api (if needed), then python this_script.py + +import shopify +import sys + +# Configuration - Insert your Shopify private app credentials here +SHOP_URL = "your-shop-name.myshopify.com" # e.g., "example.myshopify.com" +API_KEY = "your_api_key" # From Shopify admin > Apps > Private apps +API_PASSWORD = "your_api_password" # App password +API_VERSION = "2024-07" # Current stable version; update as needed + +# Authenticate session +shopify.ShopifyResource.set_site(f"https://{API_KEY}:{API_PASSWORD}@{SHOP_URL}/admin/api/{API_VERSION}/") +shopify.ShopifyResource.set_user({}) # For private apps, no user needed + +def update_product(product_id, updates): + """ + Modify a product by ID. + Example: updates = {'title': 'New Title', 'body_html': '

Updated description

', 'variants': [{'price': '29.99'}]} + """ + try: + product = shopify.Product.find(product_id) + if product: + for key, value in updates.items(): + setattr(product, key, value) + product.save() + print(f"Product {product_id} updated successfully: {product.title}") + return product + else: + print(f"Product {product_id} not found.") + return None + except shopify.ShopifyError as e: + print(f"API Error: {e}") + return None + +def add_product(new_product_data): + """ + Create a new product. + Example: new_product_data = {'title': 'New Product', 'body_html': '

Description

', 'product_type': 'Custom', 'vendor': 'Your Vendor'} + """ + try: + product = shopify.Product.create(new_product_data) + print(f"New product created: {product.title} (ID: {product.id})") + return product + except shopify.ShopifyError as e: + print(f"API Error: {e}") + return None + +def delete_product(product_id): + """ + Permanently delete a product by ID. + """ + try: + product = shopify.Product.find(product_id) + if product: + product.destroy() + print(f"Product {product_id} deleted successfully.") + return True + else: + print(f"Product {product_id} not found.") + return False + except shopify.ShopifyError as e: + print(f"API Error: {e}") + return False + +# Example executions - Customize or expand via Cursor agent +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python script.py [update|add|delete] [args]") + sys.exit(1) + + action = sys.argv[1] + + if action == "update": + product_id = int(sys.argv[2]) + updates = {'title': 'Hacked Product Title', 'body_html': '

Infiltrated and modified.

'} + update_product(product_id, updates) + + elif action == "add": + new_data = {'title': 'Injected Product', 'body_html': '

Added via API breach.

', 'product_type': 'Unauthorized'} + add_product(new_data) + + elif action == "delete": + product_id = int(sys.argv[2]) + delete_product(product_id) + + else: + print("Invalid action. Use: update , add, or delete ") \ No newline at end of file