Skip to content

Instantly share code, notes, and snippets.

@twhite96
Forked from mturilin/convert.py
Created February 15, 2024 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twhite96/58de03047ad5ddca6105d0ee86dc31ba to your computer and use it in GitHub Desktop.
Save twhite96/58de03047ad5ddca6105d0ee86dc31ba to your computer and use it in GitHub Desktop.
Converst TextExpander csv to espanso yaml
#!/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