Spaces:
Runtime error
Runtime error
#!/usr/bin/env python | |
from PyPDF2 import PdfReader | |
from PyPDF2.generic import ContentStream | |
OFFSET = 4 | |
TITLE_IDX = 0 | |
START_IDX = 1 | |
END_IDX = 2 | |
# FOOTER_TEXT = "2023 F-150 (TFD) Canada/United States of America, enUSA, Edition date: 202206, DOM" | |
FOOTER_TEXT = "2023 F-150 (TFD ) Cana da/Unit ed States of Americ a, enU SA, Edition da te: 202206 , DOM" | |
TOC = [ | |
("About Us - Raptor", 21 + OFFSET - 1 , 21 + OFFSET), | |
("Contacting Us", 22 + OFFSET - 1 , 22 + OFFSET), | |
("Introduction", 24 + OFFSET - 1 , 25 + OFFSET), | |
("Data Privacy", 29 + OFFSET - 1 , 32 + OFFSET), | |
("At a Glance - Raptor", 33 + OFFSET - 1 , 33 + OFFSET), | |
("Visual Search", 35 + OFFSET - 1 , 49 + OFFSET), | |
("Child Safety", 50 + OFFSET - 1 , 63 + OFFSET), | |
("Seatbelts", 64 + OFFSET - 1 , 71 + OFFSET), | |
("Personal Safety System", 72 + OFFSET - 1 , 72 + OFFSET), | |
("Airbags", 73 + OFFSET - 1 , 86 + OFFSET), | |
("Pedestrian Alert System - Hybrid Electric Vehicle (HEV)", 87 + OFFSET - 1 , 87 + OFFSET), | |
("911 Assist", 88 + OFFSET - 1 , 89 + OFFSET), | |
("Keys and Remote Controls", 90 + OFFSET - 1 , 98 + OFFSET), | |
("MyKey - Vehicles With: MyKey", 99 + OFFSET - 1 , 102 + OFFSET), | |
("Doors and Locks", 104 + OFFSET - 1 , 106 + OFFSET), | |
("Keyless Entry", 108 + OFFSET - 1 , 109 + OFFSET), | |
("Keyless Entry Keypad", 110 + OFFSET - 1 , 111 + OFFSET), | |
("Easy Entry and Exit", 112 + OFFSET - 1 , 112 + OFFSET), | |
("Tailgate - Vehicles With: Manual Tailgate", 113 + OFFSET - 1 , 117 + OFFSET), | |
("Tailgate - Vehicles With: Power Tailgate", 119 + OFFSET - 1 , 125 + OFFSET), | |
("Tailgate - Vehicles With: Remote Release Tailgate", 127 + OFFSET - 1 , 132 + OFFSET), | |
("Security", 134 + OFFSET - 1 , 136 + OFFSET), | |
("Power Running Boards", 138 + OFFSET - 1 , 139 + OFFSET), | |
("Steering Wheel", 140 + OFFSET - 1 , 141 + OFFSET), | |
("Adjustable Pedals", 142 + OFFSET - 1 , 142 + OFFSET), | |
("Wipers and Washers", 143 + OFFSET - 1 , 145 + OFFSET), | |
("Exterior Lighting", 147 + OFFSET - 1 , 157 + OFFSET), | |
("Interior Lighting", 159 + OFFSET - 1 , 160 + OFFSET), | |
("Windows", 161 + OFFSET - 1 , 162 + OFFSET), | |
("Interior Mirror", 163 + OFFSET - 1 , 163 + OFFSET), | |
("Exterior Mirrors", 164 + OFFSET - 1 , 165 + OFFSET), | |
("Moonroof", 166 + OFFSET - 1 , 167 + OFFSET), | |
("Instrument Cluster", 168 + OFFSET - 1 , 173 + OFFSET), | |
("Instrument Cluster Display", 175 + OFFSET - 1 , 178 + OFFSET), | |
("Personalized Settings", 179 + OFFSET - 1 , 179 + OFFSET), | |
("Trip Computer", 180 + OFFSET - 1 , 180 + OFFSET), | |
("Remote Start", 181 + OFFSET - 1 , 182 + OFFSET), | |
("Climate Control - Vehicles With: Automatic Temperature Control", 184 + OFFSET - 1 , 187 + OFFSET), | |
("Climate Control - Vehicles With: Manual Climate Control", 189 + OFFSET - 1 , 191 + OFFSET), | |
("Interior Air Quality", 192 + OFFSET - 1 , 192 + OFFSET), | |
("Front Seats", 193 + OFFSET - 1 , 200 + OFFSET), | |
("Rear Seats - Crew Cab", 202 + OFFSET - 1 , 203 + OFFSET), | |
("Rear Occupant Alert System", 205 + OFFSET - 1 , 206 + OFFSET), | |
("Memory Function", 207 + OFFSET - 1 , 207 + OFFSET), | |
("Garage Door Openeer", 208 + OFFSET - 1 , 211 + OFFSET), | |
("USB Ports", 212 + OFFSET - 1 , 213 + OFFSET), | |
("Power Outlet - Vehicles With: 120v Power Outlet", 214 + OFFSET - 1 , 215 + OFFSET), | |
("Power Outlet - Vehicles With: 12v Power Outlet", 216 + OFFSET - 1 , 216 + OFFSET), | |
("Onboard Generator", 217 + OFFSET - 1 , 223 + OFFSET), | |
("Center Console Work Surface", 225 + OFFSET - 1 , 227 + OFFSET), | |
("Wireless Accessory Charging", 228 + OFFSET - 1 , 228 + OFFSET), | |
("Storage", 229 + OFFSET - 1 , 232 + OFFSET), | |
("Starting and Stopping the Engine", 233 + OFFSET - 1 , 240 + OFFSET), | |
("Hybrid Electric Vehicle Information - Hybrid Electric Vehicle (HEV)", 244 + OFFSET - 1 , 247 + OFFSET), | |
("Auto - Start - Stop", 248 + OFFSET - 1 , 249 + OFFSET), | |
("Fuel and Refueling", 251 + OFFSET - 1 , 260 + OFFSET), | |
("Cataytic Converter", 262 + OFFSET - 1 , 262 + OFFSET), | |
("High Voltage Battery - Hybrid Electric Vehicle (HEV)", 263 + OFFSET - 1 , 263 + OFFSET), | |
("Automatic Transmission", 264 + OFFSET - 1 , 273 + OFFSET), | |
("Four-Wheel Drive", 274 + OFFSET - 1 , 280 + OFFSET), | |
("Electronic Locking Differential", 284 + OFFSET - 1 , 290 + OFFSET), | |
("Brakes", 291 + OFFSET - 1 , 292 + OFFSET), | |
("Electric Parking Brake", 294 + OFFSET - 1 , 295 + OFFSET), | |
("Reverse Braking Assist", 297 + OFFSET - 1 , 299 + OFFSET), | |
("Cross Traffic Braking", 301 + OFFSET - 1 , 302 + OFFSET), | |
("Hill Start Assist", 304 + OFFSET - 1 , 304 + OFFSET), | |
("Auto Hold", 305 + OFFSET - 1 , 305 + OFFSET), | |
("Traction Control", 307 + OFFSET - 1 , 308 + OFFSET), | |
("Stability Control", 309 + OFFSET - 1 , 311 + OFFSET), | |
("Trail Control - Raptor-Tremor", 312 + OFFSET - 1 , 315 + OFFSET), | |
("Trail Turn Assist", 316 + OFFSET - 1 , 317 + OFFSET), | |
("Hill Descent Control", 318 + OFFSET - 1 , 319 + OFFSET), | |
("Steering", 320 + OFFSET - 1 , 321 + OFFSET), | |
("Parking Aids", 323 + OFFSET - 1 , 327 + OFFSET), | |
("Rear View Camera", 329 + OFFSET - 1 , 330 + OFFSET), | |
("360 Degree Camera", 332 + OFFSET - 1 , 334 + OFFSET), | |
("Active Park Assist", 336 + OFFSET - 1 , 338 + OFFSET), | |
("Cruise Control", 340 + OFFSET - 1 , 341 + OFFSET), | |
("Adaptive Cruise Control", 342 + OFFSET - 1 , 354 + OFFSET), | |
("BlueCruise", 356 + OFFSET - 1 , 360 + OFFSET), | |
("Drive Mode Control", 362 + OFFSET - 1 , 373 + OFFSET), | |
("Lane Keeping System", 375 + OFFSET - 1 , 379 + OFFSET), | |
("Blind Spot Information System", 382 + OFFSET - 1 , 386 + OFFSET), | |
("Cross Traffic Alert", 387 + OFFSET - 1 , 389 + OFFSET), | |
("Pre-Collision Assist", 390 + OFFSET - 1 , 397 + OFFSET), | |
("Driver Alert", 399 + OFFSET - 1 , 400 + OFFSET), | |
("Speed Sign Recognition", 401 + OFFSET - 1 , 402 + OFFSET), | |
("Load Carrying", 404 + OFFSET - 1 , 407 + OFFSET), | |
("Pickup Bed", 409 + OFFSET - 1 , 411 + OFFSET), | |
("Connecting a Trailer", 414 + OFFSET - 1 , 417 + OFFSET), | |
("Towing a Trailer", 418 + OFFSET - 1 , 423 + OFFSET), | |
("Integrated Trailer Brake Controller", 425 + OFFSET - 1 , 428 + OFFSET), | |
("Trailer Sway Control", 430 + OFFSET - 1 , 430 + OFFSET), | |
("Trailer Hitching Assistance", 431 + OFFSET - 1 , 433 + OFFSET), | |
("Smart Hitch", 435 + OFFSET - 1 , 437 + OFFSET), | |
("Onboard Scales", 437 + OFFSET - 1 , 437 + OFFSET), | |
("Trailer Backup Assistance", 439 + OFFSET - 1 , 447 + OFFSET), | |
("Trailer Reverse Guidance", 454 + OFFSET - 1 , 460 + OFFSET), | |
("Driving Hints", 466 + OFFSET - 1 , 473 + OFFSET), | |
("Snow Plowing - Vehicles Without: Snow Plow Mode", 475 + OFFSET - 1 , 475 + OFFSET), | |
("Snow Plowing - Vehicles With: Snow Plow Mode", 476 + OFFSET - 1 , 477 + OFFSET), | |
("Crash and Breakdown Information", 478 + OFFSET - 1 , 484 + OFFSET), | |
("Towing Your Vehicle", 485 + OFFSET - 1 , 487 + OFFSET), | |
("Fuses", 488 + OFFSET - 1 , 497 + OFFSET), | |
("Maintenance", 498 + OFFSET - 1 , 528 + OFFSET), | |
("Vehicle Care", 529 + OFFSET - 1 , 534 + OFFSET), | |
("Storing Your Vehicle", 535 + OFFSET - 1 , 536 + OFFSET), | |
("Wheel and Tire Information", 537 + OFFSET - 1 , 547 + OFFSET), | |
("Tire Care", 550 + OFFSET - 1 , 552 + OFFSET), | |
("Tire Pressue Monitoring System", 554 + OFFSET - 1 , 559 + OFFSET), | |
("Changing a Road Wheel", 561 + OFFSET - 1 , 576 + OFFSET), | |
("Capacities and Specifications", 578 + OFFSET - 1 , 619 + OFFSET), | |
("Vehicle Identification", 620 + OFFSET - 1 , 620 + OFFSET), | |
("Connected Vehicle", 621 + OFFSET - 1 , 622 + OFFSET), | |
("Vehicle Wi-Fi Hotspot", 624 + OFFSET - 1 , 625 + OFFSET), | |
("Audio System", 626 + OFFSET - 1 , 633 + OFFSET), | |
("Center Display Overview", 637 + OFFSET - 1 , 639 + OFFSET), | |
("Voice Interaction", 640 + OFFSET - 1 , 640 + OFFSET), | |
("Alexa Built-In", 642 + OFFSET - 1 , 642 + OFFSET), | |
("Phone", 644 + OFFSET - 1 , 648 + OFFSET), | |
("Bluetooth", 649 + OFFSET - 1 , 649 + OFFSET), | |
("Apps", 650 + OFFSET - 1 , 651 + OFFSET), | |
("Personal Profiles", 652 + OFFSET - 1 , 653 + OFFSET), | |
("Navigation", 654 + OFFSET - 1 , 656 + OFFSET), | |
("Vehicle Software Updates", 657 + OFFSET - 1 , 658 + OFFSET), | |
("Vehicle System Reset", 659 + OFFSET - 1 , 659 + OFFSET), | |
("Accessories", 660 + OFFSET - 1 , 660 + OFFSET), | |
("Auxiliary Switches", 661 + OFFSET - 1 , 662 + OFFSET), | |
("Warranty Terms and Conditions - Raptor", 664 + OFFSET - 1 , 664 + OFFSET), | |
("Ford Protect", 665 + OFFSET - 1 , 665 + OFFSET), | |
("Scheduled Maintenance", 667 + OFFSET - 1 , 676 + OFFSET), | |
("Decommissioning the Vehicle - Police Responder", 680 + OFFSET - 1 , 680 + OFFSET), | |
("Customer Information", 681 + OFFSET - 1 , 749 + OFFSET), | |
("Electromagnetic Compatibility", 751 + OFFSET - 1 , 751 + OFFSET), | |
] | |
reader = PdfReader("docs/2023_Ford_F-150_OM_PL3J_19A321_AA_EN_V1.pdf") | |
for chapter in TOC: | |
pages = reader.pages[chapter[START_IDX]:chapter[END_IDX]] | |
title = chapter[TITLE_IDX] | |
print(title) | |
content = "\n\n".join([p.extract_text() for p in pages]) | |
content = f"{title}\n\n{content}" | |
content = content.replace(FOOTER_TEXT, "") | |
open(f"docs/chapters/{chapter[TITLE_IDX]}.txt", "w").write(content) |