Created
June 20, 2022 08:30
-
-
Save onewesong/68c7b1ebee0401c84e4bd38006abf2c1 to your computer and use it in GitHub Desktop.
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 | |
# coding: utf-8 | |
import cson | |
def read_file(fp): | |
with open(fp) as f: | |
return f.read() | |
def write_file(fp, data): | |
with open(fp, 'w+') as f: | |
return f.write(data) | |
def convert(file): | |
d = cson.loads(read_file('notes/' + file)) | |
if not d.get("content"): | |
return | |
output = '---\n' | |
title = d['title'] | |
for char in '`[]': | |
if char in title: | |
title = "Unknown" | |
output += f"title: {title}\n" | |
output += f"updated: {d['updatedAt']}\n" | |
output += f"created: {d['createdAt']}\n" | |
output += '---\n\n' | |
output += d['content'].replace("(:storage/", "(../attachments/") | |
write_file('joplin/'+file.replace('.cson', '.md'), output) | |
if __name__ == '__main__': | |
import os | |
for file in os.listdir('notes'): | |
print(file) | |
convert(file) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment