Skip to content

Instantly share code, notes, and snippets.

@leetschau
Created September 17, 2016 10:06
Show Gist options
  • Save leetschau/2a8b8b00d42e8565b2378b74fd3f4ba1 to your computer and use it in GitHub Desktop.
Save leetschau/2a8b8b00d42e8565b2378b74fd3f4ba1 to your computer and use it in GitHub Desktop.
将dsnote里面的笔记通过`geeknote create`命令同步到Evernote上
import os
import subprocess
basedir = '/home/leo/.donno/repo'
notebook = 'dsnote'
err_coll = []
for fn in os.listdir(basedir):
print('upload %s' % fn)
fullname = os.path.join(basedir, fn)
if not os.path.isfile(fullname):
continue
raw_content = open(fullname).read().split('\n')
title = raw_content[0].split('Title: ')[1]
print('title: %s' % title)
tags = raw_content[1].split('Tags: ')[1].replace(' ', '').replace(';', ',')
print('tags: %s' % tags)
texts = [line.replace('"', '_DB_QT_') for line in raw_content[7:]]
contents = '\n'.join(texts)
#ret = subprocess.check_output('geeknote settings', shell=True)
create_cmd = 'timeout 5 geeknote create --title "%s" --content "%s" --notebook %s --tags "%s"' \
% (title, contents, notebook, tags)
#print('whole commands: %s' % create_cmd)
#ret = subprocess.check_output(create_cmd, shell=True)
#print(ret)
ret = subprocess.call(create_cmd, shell=True)
print(ret)
if ret != 0:
err_coll.append(fn)
print('notes cannot be uploaded to evernote: %s' % err_coll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment