-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautorun.py
More file actions
82 lines (63 loc) · 2.43 KB
/
autorun.py
File metadata and controls
82 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
"""
Auto-convert all XML files in the current directory to CSV format
"""
from wxr_to_csv import WXRToCSVConverter
from pathlib import Path
import sys
def auto_convert_all_xml():
"""Automatically find and convert all XML files to CSV format."""
# Initialize the converter
converter = WXRToCSVConverter()
# Find all XML files in current directory
xml_files = list(Path('.').glob('*.xml'))
if not xml_files:
print("No XML files found in current directory.")
print("To use this script:")
print("1. Export your WordPress content (Tools → Export in WordPress admin)")
print("2. Save the .xml file(s) in this directory")
print("3. Run this script again")
return
print(f"Found {len(xml_files)} XML file(s):")
for xml_file in xml_files:
print(f" - {xml_file}")
print()
converted_count = 0
failed_count = 0
for xml_file in xml_files:
try:
print(f"Converting {xml_file}...")
# Create output CSV filename
csv_file = xml_file.with_suffix('.csv')
# Convert the file
result = converter.convert_to_csv(str(xml_file), str(csv_file))
if result:
converted_count += 1
print(f"✅ Successfully converted {xml_file} → {csv_file}")
else:
print(f"⚠️ No content found in {xml_file}")
except Exception as e:
failed_count += 1
print(f"❌ Error converting {xml_file}: {e}")
print() # Add spacing between files
# Summary
print("=" * 50)
print("CONVERSION SUMMARY")
print("=" * 50)
print(f"Total XML files found: {len(xml_files)}")
print(f"Successfully converted: {converted_count}")
print(f"Failed conversions: {failed_count}")
if converted_count > 0:
print(f"\n📁 CSV files created:")
for xml_file in xml_files:
csv_file = xml_file.with_suffix('.csv')
if csv_file.exists():
print(f" - {csv_file}")
if failed_count > 0:
print(f"\n⚠️ {failed_count} file(s) failed to convert. Check the error messages above.")
return 1
else:
print(f"\n🎉 All files converted successfully!")
return 0
if __name__ == '__main__':
exit(auto_convert_all_xml())