### Clone Repository and Run Generator Script Source: https://context7.com/asatillo/xml_generator/llms.txt Instructions for setting up and running the XML generator script from the command line. Includes cloning the repository, placing the database, and optional configuration adjustments. ```bash # 1. Clone the repository git clone https://github.com/Asatillo/butopea_xml_generator.git cd butopea_xml_generator # 2. Place your SQLite database in the same directory cp /path/to/your/data.sqlite . # 3. (Optional) Adjust filenames in configs.py # DATABASE_FILE = 'data.sqlite' # XML_FILENAME = 'feed.xml' # 4. Run the generator python generator.py # 5. Verify output ls -lh feed.xml # -rw-r--r-- 1 user group 48K Jan 01 12:00 feed.xml ``` -------------------------------- ### Query Product Data from SQLite Source: https://context7.com/asatillo/xml_generator/llms.txt Connects to a SQLite database and fetches active product data using a multi-table JOIN. Includes error handling for database operations. Ensure the database schema matches the query's expectations. ```python import sqlite3 def make_query(database): """ Connect to the SQLite database and fetch all active products. :param database: Path to the .sqlite database file :return: List of tuples — each tuple represents one product row: (id, title, description, link, image_link, additional_images, availability, price, brand, condition) """ conn = sqlite3.connect(database) cursor = conn.cursor() try: cursor.execute(''' SELECT product.product_id AS id, product_description.name AS title, product_description.description AS description, "https://butopea.com/p/" || product.product_id AS link, "https://butopea.com/" || product.image AS image_link, GROUP_CONCAT("https://butopea.com/" || product_image.image) AS additional_images, CASE WHEN product.quantity > 0 THEN "in_stock" ELSE "out_of_stock" END AS availability, ROUND(product.price, 2) || " HUF" AS price, manufacturer.name AS brand, "new" AS condition FROM product LEFT JOIN product_image ON product.product_id = product_image.product_id LEFT JOIN product_description ON product.product_id = product_description.product_id LEFT JOIN manufacturer ON product.manufacturer_id = manufacturer.manufacturer_id WHERE status = "1" GROUP BY product.product_id ''') return cursor.fetchall() except Exception as e: print("An error occurred", e) return [] # Example usage products = make_query('data.sqlite') print(f"Fetched {len(products)} active products") # Sample output tuple: # ('42', 'Blue Widget', 'A sturdy blue widget.', 'https://butopea.com/p/42', # 'https://butopea.com/image/widget.jpg', # 'https://butopea.com/image/widget_a1.jpg,https://butopea.com/image/widget_a2.jpg', # 'in_stock', '1990.0 HUF', 'WidgetBrand', 'new') ``` -------------------------------- ### Build and Write XML Product Feed Source: https://context7.com/asatillo/xml_generator/llms.txt Generates an XML product feed by querying a database and constructing an ElementTree. Handles multiple additional images per product. Writes the output in binary mode. ```python import xml.etree.ElementTree as ET from configs import DATABASE_FILE, XML_FILENAME def get_xml(filename_save): """ Generate an XML product feed from the SQLite database and save it to disk. :param filename_save: Output path for the XML file (e.g., 'feed.xml') """ root = ET.Element("products") products = make_query(DATABASE_FILE) for product in products: prod = ET.SubElement(root, "product") ET.SubElement(prod, "id").text = product[0] ET.SubElement(prod, "title").text = product[1] ET.SubElement(prod, "description").text = product[2] ET.SubElement(prod, "link").text = product[3] ET.SubElement(prod, "image_link").text = product[4] # Additional images — one per image URL if product[5]: for img_url in product[5].split(','): ET.SubElement(prod, "additional_image_link").text = img_url ET.SubElement(prod, "availability").text = product[6] ET.SubElement(prod, "price").text = product[7] ET.SubElement(prod, "brand").text = product[8] ET.SubElement(prod, "condition").text = product[9] tree = ET.ElementTree(root) with open(filename_save, 'wb') as f: tree.write(f) # Run directly get_xml(XML_FILENAME) # Expected output file — feed.xml: # # # 42 # Blue Widget # A sturdy blue widget. # https://butopea.com/p/42 # https://butopea.com/image/widget.jpg # https://butopea.com/image/widget_a1.jpg # https://butopea.com/image/widget_a2.jpg # in_stock # 1990.0 HUF # WidgetBrand # new # # ... # ``` -------------------------------- ### Configure Database and Output File Paths Source: https://context7.com/asatillo/xml_generator/llms.txt Defines the SQLite database file path and the output XML filename. Edit these constants to change the input source or output destination. ```python # configs.py # Name/path of the SQLite database file to read from DATABASE_FILE = 'data.sqlite' # Name/path of the XML file to write product data to XML_FILENAME = 'feed.xml' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.