Last active
May 30, 2023 23:54
-
-
Save simonwagner/0ca407314bea9862ce6b15903fdcca87 to your computer and use it in GitHub Desktop.
Convert Avid ALE files to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from collections import OrderedDict | |
from itertools import dropwhile, izip | |
import csv | |
import argparse | |
import os.path | |
argparser = argparse.ArgumentParser() | |
argparser.add_argument("ale_file", metavar="ALE", type=argparse.FileType(mode="rb")) | |
argparser.add_argument("csv_file", metavar="CSV", type=argparse.FileType(mode="wb"), nargs="?", default=None) | |
def main(): | |
args = argparser.parse_args() | |
columns, data = convert_ale_to_dict(args.ale_file) | |
args.ale_file.close() | |
if args.csv_file is not None: | |
csv_file = args.csv_file | |
else: | |
pre, ext = os.path.splitext(args.ale_file.name) | |
csv_path = pre + ".csv" | |
csv_file = open(csv_path, mode="wb") | |
dump_csv(csv_file, columns, data) | |
csv_file.close() | |
def convert_ale_to_dict(f): | |
f_iter = iter(f) | |
f_iter = dropwhile(lambda line: line != "Column\n", f_iter) | |
column_line = next_or_none(f_iter) | |
if column_line is None: | |
raise Exception("No columns found") | |
column_names_line = next_or_none(f_iter) | |
if column_names_line is None: | |
raise Exception("No values for columns") | |
columns = column_names_line.replace("\n", "").split("\t") | |
f_iter = dropwhile(lambda line: line != "Data\n", f_iter) | |
data_line = next_or_none(f_iter) | |
if data_line is None: | |
raise Exception("No data found") | |
data = [] | |
for data_values_line in f_iter: | |
values = data_values_line.replace("\n", "").split("\t") | |
values_dict = OrderedDict(izip(columns, values)) | |
data.append(values_dict) | |
return (columns, data) | |
def dump_csv(f, columns, data): | |
dw = csv.DictWriter(f, fieldnames=columns) | |
dw.writeheader() | |
dw.writerows(data) | |
def next_or_none(iter): | |
try: | |
return next(iter) | |
except StopIteration: | |
return None | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Howdy y'all! I enhanced this code and have if convert stuff from Alexa camera's to CSV for Resolve! Check it out:
https://github.com/jaminmc/ale2ResolveCSV
It also runs on the latest Python