Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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}")
@Kmfernan5
Copy link

Kmfernan5 commented Apr 20, 2022

How do you run this? Im getting an error? @mturilin

PS C:\Users***> python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

convert.py
Traceback (most recent call last):
File "", line 1, in
NameError: name 'convert' is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment