-
-
Save jamtur01/a8d73c29baa7fd0ed775df3b0e708fc3 to your computer and use it in GitHub Desktop.
Converst TextExpander csv to espanso yaml
This file contains hidden or 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/python3 | |
import yaml | |
import sys | |
import csv | |
# create root yaml | |
matches = [] | |
# open file | |
filename = sys.argv[1] | |
with open(filename, newline='') as csvfile: | |
csv_reader = csv.reader(csvfile, delimiter=',', quotechar='"') | |
for row in csv_reader: | |
matches.append({ | |
'trigger': row[0], | |
'replace': row[1] | |
}) | |
# dump results into a file | |
espanso_root = { | |
'parent': 'default', | |
'matches': matches | |
} | |
new_filename = filename[:-4]+".yml" | |
dump = yaml.dump(espanso_root, encoding='utf-8', allow_unicode=True) | |
print(dump) | |
with open(new_filename,'wb') as new_file: | |
new_file.write(dump) | |
print(F"Created {new_filename}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment