def sync(self): """ Synchronize files to notes TODO: add two way sync with meta support TODO: add specific notebook support """ if not self.all_set: return files = self._get_files() notes = self._get_notes() for f in files: has_note = False meta = self._parse_meta(self._get_file_content(f['path'])) title = f['name'] if 'title' not in meta else meta['title'].strip() tags = None if 'tags' not in meta else meta['tags'] \ .replace('[', '').replace(']','').split(',') tags = None if tags == '' else map(lambda x:x.strip(), tags) note = None if self.format == 'html': meta['mtime'] = f['mtime'] note = self._html2note(meta) for n in notes: if title == n.title: has_note = True if f['mtime'] > n.updated: if self.format == 'html': gn = GeekNote() note.guid = n.guid gn.getNoteStore().updateNote(gn.authToken, note) logger.info('Note "{0}" was updated'.format(note.title)) else: self._update_note(f, n, title, meta['content'], tags) break if not has_note: if self.format == 'html': gn = GeekNote() gn.getNoteStore().createNote(gn.authToken, note) logger.info('Note "{0}" was created'.format(note.title)) else: self._create_note(f, title, meta['content'], tags) if self.twoway: for n in notes: has_file = False for f in files: if f['name'] == n.title: has_file = True if f['mtime'] < n.updated: self._update_file(f, n) break if not has_file: self._create_file(n) logger.info('Sync Complete')
def sync(self): """ Synchronize files to notes TODO: add two way sync with meta support TODO: add specific notebook support """ if not self.all_set: return files = self._get_files() notes = self._get_notes() if not self.download_only: for f in files: has_note = False meta = self._parse_meta(self._get_file_content(f['path'])) title = f['name'] if 'title' not in meta else meta['title'].strip() tags = None if 'tags' not in meta else meta['tags'] \ .replace('[', '').replace(']', '').split(',') tags = None if not tags else map(lambda x: x.strip(), tags) meta['tags'] = tags meta['title'] = title note = None if self.format == 'html': meta['mtime'] = f['mtime'] note = self._html2note(meta) for n in notes: if title == n.title: has_note = True if f['mtime'] > n.updated: if self.format == 'html': gn = GeekNote() note.guid = n.guid gn.getNoteStore().updateNote(gn.authToken, note) logger.info('Note "{0}" was updated'.format(note.title)) else: self._update_note(f, n, title, meta['content'], tags) break if not has_note: if self.format == 'html': gn = GeekNote() gn.getNoteStore().createNote(gn.authToken, note) logger.info('Note "{0}" was created'.format(note.title)) else: self._create_note(f, title, meta['content'], tags) if self.twoway or self.download_only: for n in notes: has_file = False for f in files: if f['name'] == n.title: has_file = True if f['mtime'] < n.updated: self._update_file(f, n) break if not self.nodownsync: if not has_file: self._create_file(n) logger.info('Sync Complete')
def sync(self): """ Synchronize files to notes TODO: add two way sync with meta support TODO: add specific notebook support """ if not self.all_set: return files = self._get_files() notes = self._get_notes() if not self.download_only: for f in files: has_note = False content = self._get_file_content(f['path'], f['format']) meta = self._parse_meta(content, f['format']) title = f['name'] if 'title' not in meta else meta[ 'title'].strip() tags = None if 'tags' not in meta else meta['tags'] \ .replace('[', '').replace(']', '').split(',') tags = None if not tags else map(lambda x: x.strip(), tags) meta['tags'] = tags meta['title'] = title note = None meta['mtime'] = f['mtime'] if f['format'] == 'html': note = self._html2note(meta) elif f['format'] == 'markdown': # note = self._md2note(meta) # as Editor.textToENML converts markdown to HTML, reuse note = self._html2note(meta) else: assert False, "unsupported format for upload: %s" % f[ 'format'] for n in notes: if title == n.title: has_note = True if f['mtime'] > n.updated: if self.format == 'html': gn = GeekNote( sleepOnRateLimit=self.sleep_on_ratelimit) note.guid = n.guid gn.getNoteStore().updateNote( gn.authToken, note) logger.info('Note "{0}" was updated'.format( note.title)) else: self._update_note(f, n, title, meta['content'], tags) break if not has_note: if self.format == 'html': gn = GeekNote(sleepOnRateLimit=self.sleep_on_ratelimit) gn.getNoteStore().createNote(gn.authToken, note) logger.info('Note "{0}" was created'.format( note.title)) else: self._create_note(f, title, meta['content'], tags) if self.twoway or self.download_only: for n in notes: has_file = False for f in files: if f['name'] == n.title: has_file = True if f['mtime'] < n.updated: self._update_file(f, n) break if not self.nodownsync: if not has_file: self._create_file(n) logger.info('Sync Complete')
def sync(self): """ Synchronize files to notes TODO: add two way sync with meta support TODO: add specific notebook support """ if not self.all_set: return files = self._get_files() notes = self._get_notes() if not self.download_only: for f in files: has_note = False meta = self._parse_meta(self._get_file_content(f["path"])) title = f["name"] if "title" not in meta else meta[ "title"].strip() tags = (None if "tags" not in meta else meta["tags"].replace( "[", "").replace("]", "").split(",")) tags = None if not tags else map(lambda x: x.strip(), tags) meta["tags"] = tags meta["title"] = title note = None if self.format == "html": meta["mtime"] = f["mtime"] note = self._html2note(meta) for n in notes: if title == n.title: has_note = True if f["mtime"] > n.updated: if self.format == "html": gn = GeekNote( sleepOnRateLimit=self.sleep_on_ratelimit) note.guid = n.guid gn.getNoteStore().updateNote( gn.authToken, note) logger.info('Note "{0}" was updated'.format( note.title)) else: self._update_note(f, n, title, meta["content"], tags) break if not has_note: if self.format == "html": gn = GeekNote(sleepOnRateLimit=self.sleep_on_ratelimit) gn.getNoteStore().createNote(gn.authToken, note) logger.info('Note "{0}" was created'.format( note.title)) else: self._create_note(f, title, meta["content"], tags) if self.twoway or self.download_only: for n in notes: has_file = False for f in files: if f["name"] == n.title: has_file = True if f["mtime"] < n.updated: self._update_file(f, n) break if not self.nodownsync: if not has_file: self._create_file(n) logger.info("Sync Complete")