Skip to content

Instantly share code, notes, and snippets.

@nicolevanderhoeven
Created December 15, 2020 20:59
Show Gist options
  • Save nicolevanderhoeven/8d089da1617cdbce13dcd406d1d0b960 to your computer and use it in GitHub Desktop.
Save nicolevanderhoeven/8d089da1617cdbce13dcd406d1d0b960 to your computer and use it in GitHub Desktop.
Reformat exported Markdown file from YiNote for importing into Roam Research
# Parses a .md generated by [YiNote](https://yinote.co/) and reformats it for export into [Roam Research](https://roamresearch.com).
# Prereq: Input .md file in the same folder
# Run this and pipe the output to a file you specify, i.e. `python3 yinotetoroam.py > output.md`
# Import `output.md` to Roam.
import re
import datetime
import glob
try:
filename = glob.glob('*.md')
fhand = open(filename[0])
except:
print('File cannot be opened:', fname)
exit()
# Print Roam boilerplate
print('Date:: ')
print('Tags:: #TVZ')
for line in fhand:
# Finds the line that has the title of the video, usually the second line
if line.startswith('<!-- # '):
# Print Source line
link = re.findall('<!-- # (.+) -->', line)
print('Source:: ',''.join(link))
# Find url in link and embed it as a YouTube video
url = re.findall('\((.+)\)', ''.join(link))
print('{{[[youtube]]: ',''.join(url),'}}\n')
continue
if line.startswith('\n'):
continue
if line.startswith('<!-- Generated'):
continue
if not line.startswith('<!-- '):
print('\t* ', line)
continue
timestamp = re.findall('<!-- ## (.+) -->', line)
print(''.join(timestamp))
@englerg
Copy link

englerg commented Dec 23, 2020

Hi Nicole.
Thanks for the script and the explanation. My question is, what do I do with that script? Where do I save it? How do I run it on the exported file?

Best wishes for the coming holidays,
Guy

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