Not sure if its an issue with an independent function or an issue with data extraction in general- `
def read_file(file_path):
if not os.path.exists(file_path):
raise FileNotFoundError(f"File not found: {file_path}")
with open(file_path, 'r') as file:
return file.readlines()
# Parse Baselight data
def parse_baselight(data):
parsed_frames = []
for line in data:
if "<err>" in line:
continue
components = line.strip().split()
if len(components) < 2:
continue
filename = components[0]
frame_data = components[1:]
numeric_frames = sorted(set(validate_numeric(frame) for frame in frame_data if validate_numeric(frame)))
if numeric_frames:
frames = format_frames(numeric_frames)
parsed_frames.append((filename, frames))
return parsed_frames
def validate_numeric(value):
try:
return int(value)
except ValueError:
return None
def format_frames(frames):
ranges = []
start = frames[0]
end = frames[0]
for i in range(1, len(frames)):
if frames[i] == end + 1:
end = frames[i]
else:
ranges.append(f"{start}-{end}" if start != end else f"{start}")
start = frames[i]
end = frames[i]
ranges.append(f"{start}-{end}" if start != end else f"{start}")
return ", ".join(ranges)
def parse_xytech(data):
parsed_orders = []
for line in data:
if '/' in line:
components = line.strip().split('/')
location = components[1].strip()
workorder = components[-1].strip()
parsed_orders.append((location, workorder))
return parsed_orders
def populate_database(baselight_data, xytech_data):
conn = sqlite3.connect("thecrucible_databasedb")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS Baselight (
Location TEXT,
Frames TEXT
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS Xytech (
Location TEXT,
Workorder TEXT
)
""")
cursor.executemany("INSERT INTO Baselight (Location, Frames) VALUES (?, ?)", baselight_data)
cursor.executemany("INSERT INTO Xytech (Location, Workorder) VALUES (?, ?)", xytech_data)
conn.commit()
conn.close()
def get_video_length(video_path):
result = subprocess.run(
[
"ffprobe",
"-i", video_path,
"-v", "error",
"-show_entries", "format=duration",
"-of", "default=noprint_wrappers=1:nokey=1"
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
try:
return float(result.stdout.strip())
except ValueError:
print("Error extracting video length.")
return 0
def find_matching_ranges(video_length, frame_ranges):
matching_ranges = []
fps = 24
video_frames = int(video_length * fps)
for frame_range in frame_ranges:
if '-' in frame_range:
start, end = map(int, frame_range.split('-'))
else:
start = end = int(frame_range)
if start <= video_frames and end <= video_frames:
matching_ranges.append(frame_range)
return matching_ranges
def export_to_xls(data, output_path):
wb = Workbook()
ws = wb.active
ws.title = "Matched Data"
ws.append(["Filename", "Frame Range"])
for row in data:
ws.append(row)
wb.save(output_path)
def export_unused_to_csv(unused_data, output_path):
with open(output_path, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Filename", "Frame Range"])
writer.writerows(unused_data)
`
`
I am writing a Python script to process metadata from two text files (Baselight and Xytech) and a video file. The script performs the following operations:
Reads and parses metadata from Baselight and Xytech text files.
Populates an SQLite database with this metadata.
Processes the video to find matching frame ranges.
Exports matched data to an Excel file (output.xls) and unused data to a CSV file (unused.csv).
The script works without any crashes, but all output files (output.xls, unused.csv, and thecrucible_databasedb) are corrupted or unusable:
The database file cannot be opened in a SQLite viewer.
The Excel file (output.xls) shows errors when opened in Excel.
The CSV file contains garbled or invalid data.
Steps I’ve Taken:
Debugged the parsed data and confirmed it is in the correct format.
Added error handling for database inserts and file writing operations.
Verified permissions for writing to the output directory.
Cleared previous corrupted files before running the script again.
Tested with minimal, valid input files to isolate the issue