I have been writing this code, and I cannot figure out how to get the frame ranges
Question:
I have been writing this code, and I cannot figure out how to get the frame ranges or individual frame to display on my csv file. It displays everything except the frames that need to be fixed. How can I proceed with this? I have zero errors when running. In Frames to Fix, it just shows " []"
It should be able to print out like the example below.
The directions state:
Frames and frame ranges processed in consecutive/numerical order shown (from baselight_export.txt) as either:
ranges (i.e /filesystem/barbie/PartA/1920x1080 32-35)
individually (i.e /filesystem/barbie/PartA/1920x1080 41)
Frames shown need to reflect their proper location and not mix with ranges from another location
import csv
def baselight_export(file_path):
with open(file_path, 'r') as file_data1:
file_data1 = file_data1.read().splitlines()
parsed_1 = {}
current_location = None
for line in file_data1:
if line.startswith('/'):
current_location = line
parsed_1[current_location] = []
else:
frames = line.split()
parsed_1[current_location].extend(frames)
return parsed_1
def xytech_file(file_path):
with open(file_path, 'r') as file_data2:
file_data2 = file_data2.read().splitlines()
parsed_2 = {
'Producer': None,
'Operator': None,
'Job': None,
'Notes': "", # Initialize 'Notes' as an empty string
'Locations': [],
'Frames': []
}
notes_started = False # Flag to detect when Notes section starts
for line in file_data2:
if line.startswith('Producer:'):
parsed_2['Producer'] = line.split(': ')[1]
elif line.startswith('Operator:'):
parsed_2['Operator'] = line.split(': ')[1]
elif line.startswith('Job:'):
parsed_2['Job'] = line.split(': ')[1]
elif line.startswith('Notes:'):
notes_started = True
notes_parts = line.split(': ', 1)
if len(notes_parts) > 1:
parsed_2['Notes'] = notes_parts[1]
else:
parsed_2['Notes'] = "" # Set 'Notes' to an empty string if no content is found
elif notes_started and line.strip(): # Check if Notes section has started and the line is not empty
if parsed_2['Notes']:
parsed_2['Notes'] += '\n' # Add a newline if there's already some content in Notes
parsed_2['Notes'] += line.strip()
elif line.startswith('/'):
parsed_2['Locations'].append(line)
return parsed_2
def process(data1, data2):
processed = []
for xytech_location in data2['Locations']:
xytech_location = xytech_location.strip()
matching_frames = data1.get(xytech_location, [])
frame_ranges = []
individual_frames = []
current_start = None
current_end = None
for frame in matching_frames:
if '-' in frame:
start, end = map(int, frame.split('-'))
if current_start is None:
current_start = start
current_end = end
elif start == current_end + 1:
current_end = end
else:
frame_ranges.append(f"{current_start}-{current_end}")
current_start = start
current_end = end
else:
individual_frames.append(frame)
if current_start is not None:
frame_ranges.append(f"{current_start}-{current_end}")
frames_to_fix = frame_ranges + individual_frames
processed_item = {
'Producer': data2['Producer'],
'Operator': data2['Operator'],
'Job': data2['Job'],
'Notes': data2['Notes'],
'Show Location': xytech_location,
'Frames to Fix': frames_to_fix,
}
processed.append(processed_item)
return processed
def export(data, output_file):
if data:
with open(output_file, 'w', newline='') as file:
header = data[0].keys() # Extract keys from the first data item
writer = csv.DictWriter(file, fieldnames=header)
writer.writeheader() # Write the header row
for row in data:
writer.writerow(row)
else:
print("No data to export")
if __name__ == "__main__":
baselight_export_file = "Baselight_export.txt"
xytech_file_name = "Xytech.txt"
output_file_data = "output.csv"
data1_file = baselight_export(baselight_export_file)
data2_file = xytech_file(xytech_file_name)
processed_data = process(data1_file, data2_file)
export(processed_data, output_file_data)
The full description for instructions say : Import file created from baselight (Baselight_export.txt)
Import xytech work order (Xytech.txt)
Script will parse data
Computation done to match shareholder request, to replace file system from local baselight to facility storage (remember color correcter's prefer local storage for bandwidth issues)
Remember we are dealing with 3rd party data, so some errors in the data might occur and you have to deal with it (i.e )
Export CSV file ('/' indicates columns): Line 1: Producer / Operator / job /notes Line 4: show location / frames to fix Frames and frame ranges processed in consecutive/numerical order shown (from baselight_export.txt) as either: ranges (i.e /filesystem/barbie/PartA/1920x1080 32-35) individually (i.e /filesystem/barbie/PartA/1920x1080 41) Frames shown need to reflect their proper location and not mix with ranges from another location