Created
September 24, 2020 08:37
-
-
Save mwielondek/85f8ca2b89427e4d22c8c562d7e4a3ea to your computer and use it in GitHub Desktop.
Transform csv-export from Airtable onto Roam readable format with proper indentation
This file contains 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/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