def write_file(file_path, text, echo=False, append=False, mode=None,
    encoding='utf8'):
    """Write text to a file"""
    if echo:
        print('Saving to ' + file_path)
    mode = mode if mode else 'a' if append else 'w'
    f = open(file_path, mode, encoding=encoding)
    f.write(text)
    f.close()
