Skip to content

Instantly share code, notes, and snippets.

@henryscala
Created May 25, 2016 06:50
Show Gist options
  • Save henryscala/6b86b3433b59597c96c4be5685a422fb to your computer and use it in GitHub Desktop.
Save henryscala/6b86b3433b59597c96c4be5685a422fb to your computer and use it in GitHub Desktop.
Program to convert yaml to csv. only make sense for me.
input_lines = []
with open("account.yml",mode='r',encoding='utf-8') as f:
input_lines = f.readlines()
input_lines = [line.strip() for line in input_lines if line.strip() != '']
entries = []
entry = []
for line in input_lines:
if line == '-':
if len(entry) != 0:
entries.append(entry)
entry = []
else:
pass
else:
entry.append(line)
if len(entry) != 0:
entries.append(entry)
accounts=[]
for entry in entries:
account={}
for line in entry:
name,value=line.split(':',1)
account[name.strip()]=value.strip()
accounts.append(account)
def output( accounts ) :
with open('account.csv',mode='w',encoding='utf-8') as f:
print('# where','username','password','class','notes',sep=' | ',file=f)
print('',file=f)
for account in accounts:
print(account['where'],account['username'],account['password'],account['class'],account['notes'],sep=' | ',file=f)
print('',file=f)
output(accounts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment