Получение поврежденных выходных файлов из моей программы python/sqlPython

Программы на Python
Ответить
Anonymous
 Получение поврежденных выходных файлов из моей программы python/sql

Сообщение Anonymous »

Не уверен, связана ли это с независимой функцией или с извлечением данных в целом — `

Код: Выделить всё

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 "" 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 

Подробнее здесь: [url]https://stackoverflow.com/questions/79264183/getting-corrupted-output-files-from-my-program-python-sql[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»