def get_filename(metadata, directory=None, ext="txt"):
    metadata = metadata.copy()
    name = metadata.pop("name", "data")
    directory = metadata.pop("directory", directory)
    try:
        timestamp = metadata.pop("timestamp")
    except KeyError:
        tstring = ""
    else:
        tstring = timestamp.strftime("+%Y%m%d%H%M%S")

    mmd = []
    for key in sorted(metadata.keys()):
        value = metadata[key]
        if type(value) is str:
            value = value.upper()
        mmd.append("%s%s" % (key.lower(), value))

    fname = "%s%s+%s.%s" % ( name, tstring, "+".join(mmd), ext)
    if directory:
        return os.path.join(directory, fname)
    else:
        return fname
Construct data file name from a metadata dictionary.
dataset/ETHPy150Open kdart/pycopia/QA/pycopia/datafile.py/get_filename