Skip to content

Instantly share code, notes, and snippets.

@mwielondek
Created September 24, 2020 08:37
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 mwielondek/85f8ca2b89427e4d22c8c562d7e4a3ea to your computer and use it in GitHub Desktop.
Save mwielondek/85f8ca2b89427e4d22c8c562d7e4a3ea to your computer and use it in GitHub Desktop.
Transform csv-export from Airtable onto Roam readable format with proper indentation
#!/usr/bin/env python3
# For transforming export from Airtable to Roam
import sys, re
filename = sys.argv[1]
filename_out = sys.argv[2]
with open(filename, 'r') as my_file:
str = my_file.read()
# Remove dashes and empty lines
str = re.sub(r"(?m)^\-{2,}$", "", str)
str = re.sub(r"(?m)^\s$", "", str)
# Capture just the name and notes (first two columns)
pat = r"^(.+),\"(?s:(.+?))\"(?!\"),.+$"
matches = re.findall(pat, str, flags=(re.MULTILINE))
print("Found {} records".format(len(matches)))
out = '\n'.join(["{}\n\t{}".format(title, note.replace('\n','\n\t')) for title, note in matches])
with open(filename_out, 'w') as f:
f.write(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment