Initialisation depot
This commit is contained in:
75
AliExpress/test_parser.py
Normal file
75
AliExpress/test_parser.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test script to parse HTML and display extracted data without database
|
||||
"""
|
||||
|
||||
from parse_orders import parse_orders_html
|
||||
import json
|
||||
|
||||
def test_parser():
|
||||
"""
|
||||
Test the HTML parser and display results
|
||||
"""
|
||||
html_file = r'c:\Users\s.noel\Documents\Projets\AliExpress\Commandes.htm'
|
||||
|
||||
print("=" * 80)
|
||||
print("AliExpress Order Parser - Test Mode")
|
||||
print("=" * 80)
|
||||
|
||||
print(f"\nParsing HTML file: {html_file}")
|
||||
orders = parse_orders_html(html_file)
|
||||
|
||||
print(f"\nFound {len(orders)} order items\n")
|
||||
|
||||
# Display all orders
|
||||
for i, order in enumerate(orders, 1):
|
||||
print(f"\n{'=' * 80}")
|
||||
print(f"Order Item #{i}")
|
||||
print(f"{'=' * 80}")
|
||||
print(f"Order Date: {order['orderDate']}")
|
||||
print(f"Order Number: {order['orderNumber']}")
|
||||
print(f"Order URL: {order['orderURL']}")
|
||||
print(f"Item Description: {order['itemDesc'][:80] if order['itemDesc'] else 'N/A'}...")
|
||||
print(f"Item Price: {order['itemPrice']} EUR")
|
||||
print(f"Item Quantity: {order['itemQuantity']}")
|
||||
print(f"Item Image URL: {order['itemImageURL'][:80] if order['itemImageURL'] else 'N/A'}...")
|
||||
print(f"Order Total: {order['orderTotal']} EUR")
|
||||
|
||||
# Summary statistics
|
||||
print(f"\n{'=' * 80}")
|
||||
print("SUMMARY STATISTICS")
|
||||
print(f"{'=' * 80}")
|
||||
print(f"Total Items: {len(orders)}")
|
||||
|
||||
unique_orders = set(o['orderNumber'] for o in orders if o['orderNumber'])
|
||||
print(f"Unique Orders: {len(unique_orders)}")
|
||||
|
||||
total_amount = sum(o['orderTotal'] for o in orders if o['orderTotal'])
|
||||
print(f"Total Amount: {total_amount:.2f} EUR")
|
||||
|
||||
# Save to JSON file for inspection
|
||||
json_file = r'c:\Users\s.noel\Documents\Projets\AliExpress\orders_extracted.json'
|
||||
with open(json_file, 'w', encoding='utf-8') as f:
|
||||
# Convert Decimal to float for JSON serialization
|
||||
orders_json = []
|
||||
for order in orders:
|
||||
order_copy = order.copy()
|
||||
if order_copy['itemPrice']:
|
||||
order_copy['itemPrice'] = float(order_copy['itemPrice'])
|
||||
if order_copy['orderTotal']:
|
||||
order_copy['orderTotal'] = float(order_copy['orderTotal'])
|
||||
orders_json.append(order_copy)
|
||||
|
||||
json.dump(orders_json, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"\nExtracted data saved to: {json_file}")
|
||||
print("\nTest completed successfully!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
test_parser()
|
||||
except Exception as e:
|
||||
print(f"\nError during testing: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user