# Import the necessary modules from the squareup library and uuid module from square.client import Client import os from dotenv import load_dotenv import uuid import datetime load_dotenv() now = datetime.datetime.utcnow() formatted_time = now.isoformat(timespec='microseconds') # Create a client object with your sandbox access token and environment client = Client( access_token=os.environ['SQUARE_ACCESS_TOKEN'], environment='sandbox' ) # Create a dictionary of food items with name and price as keys food_items = { "pizza": 10.00, "burger": 8.00, "salad": 6.00, "orange juice": 2.00, "iced tea": 3.00, "Ice coffee": 3.00, "Chicken": 5.00, "Steak": 10.00, "Mashed Potatoes": 4.00, "Soup": 2.00, "Sandwich": 5.50, "Pasta": 3.50, "Coffee": 3.00, "Cappuccino": 3.00, "Latte": 3.00, "Americano": 3.00, "Hot Chocolate": 3.00, "Muffin": 4.00, "Cookie": 2.00, "Croissant": 3.00, "Tea": 2.00, "Apple Juice": 2.00 } # Iterate over the food items dictionary for name, price in food_items.items(): idempotency_key = str(uuid.uuid4()) # Create an item variation for the item variation = { 'type': 'ITEM_VARIATION', 'id': f'#{str(uuid.uuid4())}', 'item_variation_data': { 'item_id': f'#{name}', 'pricing_type': 'FIXED_PRICING', 'price_money': { 'amount': int(price * 100), # Convert price to cents 'currency': 'USD' } } } # Create the catalog object and retrieve the catalog object id catalog_object = { 'idempotency_key': idempotency_key, 'object': { 'id': f'#{name}', 'type': 'ITEM', 'item_data': { 'name': name, 'variations': [variation] } } } response = client.catalog.upsert_catalog_object(body=catalog_object) print("\nCATALOGUE STATUS:", response.status_code) print("\nCATALOGUE RESPONSE:", response.body) catalog_object_id = response.body['catalog_object']['item_data']['variations'][0]['id'] created_at = response.body['catalog_object']['created_at'] # Create an inventory adjustment for the catalog object inventory_adjustment = { 'idempotency_key': idempotency_key, 'changes': [ { 'type': 'PHYSICAL_COUNT', 'physical_count': { 'catalog_object_id': catalog_object_id, 'state': 'IN_STOCK', 'location_id': 'LFA70NPRQAEV1', 'quantity': '53', 'occurred_at': created_at } } ], 'ignore_unchanged_counts': True } # Apply the inventory adjustment try: response = client.inventory.batch_change_inventory( inventory_adjustment) print("\nINVENTORY STATUS:", response.status_code) print("\nINVENTORY RESPONSE", response.body) print(f"Added {name} to inventory successfully.") except: continue