def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=None, note=None): result = {"title": title, "content": content, "tags": tags, "notebook": notebook, "resources": resources} result = tools.strip(result) # if get note without params if note and title is None and content is None and tags is None and notebook is None: content = config.EDITOR_OPEN if title is None and note: result["title"] = note.title if content: if content != config.EDITOR_OPEN: if isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = Editor.textToENML(content) result["content"] = content if tags: result["tags"] = tools.strip(tags.split(",")) if notebook: notepadGuid = Notebooks().getNoteGUID(notebook) if notepadGuid is None: newNotepad = Notebooks().create(notebook) notepadGuid = newNotepad.guid result["notebook"] = notepadGuid logging.debug("Search notebook") return result
def __init__(self, pos, *groups): super(Player, self).__init__(*groups) self.pos = pos self.move_keys = { pg.K_LEFT: "left", pg.K_RIGHT: "right", pg.K_DOWN: "down", pg.K_UP: "up"} self.direct_to_velocity = { "left": (-1, 0), "right": (1, 0), "down": (0, 1), "up": (0, -1)} self.direction_stack = [] self.direction = "left" self.last_direction = self.direction img_size = (32, 36) self.image_dict = { "left": cycle(strip(GFX["ranger_f"], (0, 108), img_size, 3)), "right": cycle(strip(GFX["ranger_f"], (0,36), img_size, 3)), "down": cycle(strip(GFX["ranger_f"], (0, 72), img_size, 3)), "up": cycle(strip(GFX["ranger_f"], (0, 0), img_size, 3))} self.images = self.image_dict[self.direction] self.image = next(self.images) self.rect = self.image.get_rect(center=self.pos) self.frame_time = 60 self.frame_timer = 0 self.speed = .1 self.footprint = pg.Rect(0, 0, 30, 6) self.footprint.midbottom = self.rect.midbottom
def _createSearchRequest(self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None): request = "" if notebooks: for notebook in tools.strip(notebooks.split(',')): if notebook.startswith('-'): request += '-notebook:"%s" ' % tools.strip(notebook[1:]) else: request += 'notebook:"%s" ' % tools.strip(notebook) if tags: for tag in tools.strip(tags.split(',')): if tag.startswith('-'): request += '-tag:"%s" ' % tag[1:] else: request += 'tag:"%s" ' % tag if date: date = tools.strip(date.split('-')) try: dateStruct = time.strptime(date[0] + " 00:00:00", "%d.%m.%Y %H:%M:%S") request += 'created:%s ' % time.strftime("%Y%m%d", time.localtime(time.mktime(dateStruct))) if len(date) == 2: dateStruct = time.strptime(date[1] + " 00:00:00", "%d.%m.%Y %H:%M:%S") request += '-created:%s ' % time.strftime("%Y%m%d", time.localtime(time.mktime(dateStruct) + 60 * 60 * 24)) except ValueError, e: out.failureMessage('Incorrect date format in --date attribute. ' 'Format: %s' % time.strftime("%d.%m.%Y", time.strptime('19991231', "%Y%m%d"))) return tools.exitErr()
def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=[], note=None, reminder=None): result = { "title": title, "content": content, "tags": tags, "notebook": notebook, "resources": resources, "reminder": reminder, } result = tools.strip(result) # if get note without params if note and title is None and content is None and tags is None and notebook is None: content = config.EDITOR_OPEN if title is None and note: result['title'] = note.title if content: if content != config.EDITOR_OPEN: if isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = Editor.textToENML(content) result['content'] = content if tags: result['tags'] = tools.strip(tags.split(',')) if notebook: notepadGuid = Notebooks().getNoteGUID(notebook) if notepadGuid is None: newNotepad = Notebooks().create(notebook) notepadGuid = newNotepad.guid result['notebook'] = notepadGuid logging.debug("Search notebook") if reminder: then = config.REMINDER_SHORTCUTS.get(reminder) if then: now = int(round(time.time() * 1000)) result['reminder'] = now + then elif reminder not in [config.REMINDER_NONE, config.REMINDER_DONE, config.REMINDER_DELETE]: reminder = tools.strip(reminder.split('-')) try: dateStruct = time.strptime(reminder[0] + " " + reminder[1] + ":00", config.DEF_DATE_AND_TIME_FORMAT) reminderTime = int(round(time.mktime(dateStruct) * 1000)) result['reminder'] = reminderTime except (ValueError, IndexError): out.failureMessage('Incorrect date format in --reminder attribute. ' 'Format: %s' % time.strftime(config.DEF_DATE_FORMAT, time.strptime('199912311422', "%Y%m%d%H%M"))) return tools.exitErr() return result
def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=None, note=None): result = { "title": title, "content": content, "tags": tags, "notebook": notebook, "resources": resources if resources else [] } result = tools.strip(result) # if get note without params if note and title is None and content is None and tags is None and notebook is None: content = config.EDITOR_OPEN if title is None and note: result['title'] = note.title if content: if content == config.EDITOR_OPEN: logging.debug("launch system editor") if note: self.getEvernote().loadNoteContent(note) content = editor.edit(note.content) else: content = editor.edit() elif isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = editor.textToENML(content) result['content'] = content if tags: result['tags'] = tools.strip(tags.split(',')) if notebook: notepadGuid = Notebooks().getNoteGUID(notebook) if notepadGuid is None: newNotepad = Notebooks().create(notebook) notepadGuid = newNotepad.guid result['notebook'] = notepadGuid logging.debug("Search notebook") return result
def __init__(self, pos, *groups): super(Wolf, self).__init__(*groups) self.pos = pos self.image_dict = { (-1, 0): cycle(strip(GFX["wolfleft"], (0, 0), (64, 32), 5)), (1, 0): cycle(strip(GFX["wolfright"], (0, 0), (64, 32), 5)), (0, 1): cycle(strip(GFX["wolfdown"], (0, 0), (32, 64), 4)), (0, -1): cycle(strip(GFX["wolfup"], (0, 0), (32, 64), 4))} self.direction = choice(self.directions) self.images = self.image_dict[self.direction] self.image = next(self.images) self.rect = self.image.get_rect(center=self.pos) self.speed = 3 self.move_time = randint(500, 2000) self.frame_time = 60 self.frame_timer = 0
def _searchNote(self, note): note = tools.strip(note) # load search result result = self.getStorage().getSearch() if result and tools.checkIsInt(note) and 1 <= int(note) <= len(result.notes): note = result.notes[int(note) - 1] else: request = self._createSearchRequest(search=note) logging.debug("Search notes: %s" % request) result = self.getEvernote().findNotes(request, 20) logging.debug("Search notes result: %s" % str(result)) if result.totalNotes == 0: out.failureMessage("Notes have not been found.") return tools.exitErr() elif result.totalNotes == 1 or self.selectFirstOnUpdate: note = result.notes[0] else: logging.debug("Choose notes: %s" % str(result.notes)) note = out.SelectSearchResult(result.notes) logging.debug("Selected note: %s" % str(note)) return note
def _formatExpression(label, value): """Create an expression like label:value, attending to negation and quotes """ expression = "" # if negated, prepend that to the expression before labe, not value if value.startswith('-'): expression += '-' value = value[1:] value = tools.strip(value) # values with spaces must be quoted if ' ' in value: value = '"%s"' % value expression += '%s:%s ' % (label, value) return expression
def _get_notes(self): """ Get notes from evernote. """ keywords = 'notebook:"{0}"'.format(tools.strip(self.notebook_name)) #print GeekNote().findNotes(keywords, 10000) #try to get all notes in a notebook #assum that the notebook has less than 10000 notes noteMetadataResultSpec = NoteStore.NotesMetadataResultSpec(includeTitle=True,\ includeUpdated=True) noteList = GeekNote().findNotesMetadata(keywords, 10000, noteMetadataResultSpec) notes = noteList.notes notesSize = len(notes) while (notesSize < noteList.totalNotes): noteList = GeekNote().findNotesMetadata(keywords, 10000, offset=notesSize) notes += noteList.notes notesSize = len(notes) print notesSize return notes
def imgupload(self, title, img, description): self.connectToEvernote() filedata = open( img, 'rb').read() md5 = hashlib.md5() md5.update(filedata) hashHex = md5.hexdigest() data = Types.Data() data.size = len(filedata) data.bodyHash = hashHex data.body = filedata resource = Types.Resource() resource.data = data content = '<?xml version="1.0" encoding="UTF-8"?>' content += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd">' content += '<en-note>' content += '<en-media type="image/jpeg" hash="' + hashHex + '"/>' content += '<p>' + description + '</p>' content += '</en-note>' enmlText = { "title": title, "content": content, "resource": resource, } enmlText = tools.strip(enmlText) result = self.getEvernote().createImgNote(**enmlText) if result: out.successMessage("Note has been successfully created.") else: out.failureMessage("Error while creating the note.")
def _parseInput(self, title=None, content=None, tags=None, created=None, notebook=None, resources=[], note=None, reminder=None): result = { "title": title, "content": content, "tags": tags, "created": created, "notebook": notebook, "resources": resources, "reminder": reminder, } result = tools.strip(result) # if get note without params if (note and title is None and content is None and tags is None and created is None and reminder is None and notebook is None): content = config.EDITOR_OPEN if title is None and note: result['title'] = note.title if content: if content != config.EDITOR_OPEN: if isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = Editor.textToENML(content) result['content'] = content if tags: result['tags'] = tools.strip(tags.split(',')) if created: try: result['created'] = self._getTimeFromDate(created) except ValueError: out.failureMessage( "Incorrect date format (%s) in --created attribute. 'Format: '%s' or '%s'" % (created, time.strftime(config.DEF_DATE_FORMAT, time.strptime('20151231', "%Y%m%d")), time.strftime( config.DEF_DATE_AND_TIME_FORMAT, time.strptime('201512311430', "%Y%m%d%H%M")))) return tools.exitErr() if notebook: notepadGuid = Notebooks().getNoteGUID(notebook) if notepadGuid is None: newNotepad = Notebooks().create(notebook) notepadGuid = newNotepad.guid result['notebook'] = notepadGuid logging.debug("Search notebook") if reminder: then = config.REMINDER_SHORTCUTS.get(reminder) if then: now = int(round(time.time() * 1000)) result['reminder'] = now + then elif reminder not in [ config.REMINDER_NONE, config.REMINDER_DONE, config.REMINDER_DELETE ]: try: result['reminder'] = self._getTimeFromDate(reminder) except ValueError: out.failureMessage( "Incorrect date format (%s) in --reminder attribute. 'Format: '%s' or '%s'" % (reminder, time.strftime(config.DEF_DATE_FORMAT, time.strptime('20151231', "%Y%m%d")), time.strftime( config.DEF_DATE_AND_TIME_FORMAT, time.strptime('201512311430', "%Y%m%d%H%M")))) return tools.exitErr() return result
class Notes(GeekNoteConnector): """ Work with Notes """ findExactOnUpdate = False selectFirstOnUpdate = False def __init__(self, findExactOnUpdate=False, selectFirstOnUpdate=False): self.findExactOnUpdate = bool(findExactOnUpdate) self.selectFirstOnUpdate = bool(selectFirstOnUpdate) def _editWithEditorInThread(self, inputData, note=None): if note: self.getEvernote().loadNoteContent(note) editor = Editor(note.content) else: editor = Editor('') thread = EditorThread(editor) thread.start() result = True prevChecksum = editor.getTempfileChecksum() while True: if prevChecksum != editor.getTempfileChecksum() and result: newContent = open(editor.tempfile, 'r').read() inputData['content'] = Editor.textToENML(newContent) if not note: result = self.getEvernote().createNote(**inputData) # TODO: log error if result is False or None if result: note = result else: result = False else: result = bool(self.getEvernote().updateNote(guid=note.guid, **inputData)) # TODO: log error if result is False if result: prevChecksum = editor.getTempfileChecksum() if not thread.isAlive(): # check if thread is alive here before sleep to avoid losing data saved during this 5 secs break time.sleep(5) return result def create(self, title, content=None, tags=None, notebook=None, resource=None): self.connectToEvertone() # Optional Content. content = content or " " inputData = self._parseInput(title, content, tags, notebook, resource) print inputData if inputData['content'] == config.EDITOR_OPEN: result = self._editWithEditorInThread(inputData) else: out.preloader.setMessage("Creating note...") result = bool(self.getEvernote().createNote(**inputData)) if result: out.successMessage("Note has been successfully created.") else: out.failureMessage("Error while creating the note.") def edit(self, note, title=None, content=None, tags=None, notebook=None, resource=None): self.connectToEvertone() note = self._searchNote(note) inputData = self._parseInput(title, content, tags, notebook, resource, note) if inputData['content'] == config.EDITOR_OPEN: result = self._editWithEditorInThread(inputData, note) else: out.preloader.setMessage("Saving note...") result = bool(self.getEvernote().updateNote(guid=note.guid, **inputData)) if result: out.successMessage("Note has been successfully saved.") else: out.failureMessage("Error while saving the note.") def remove(self, note, force=None): self.connectToEvertone() note = self._searchNote(note) if not force and not out.confirm( 'Are you sure you want to ' 'delete this note: "%s"?' % note.title): return tools.exit() out.preloader.setMessage("Deleting note...") result = self.getEvernote().removeNote(note.guid) if result: out.successMessage("Note has been successful deleted.") else: out.failureMessage("Error while deleting the note.") def show(self, note, raw=None): self.connectToEvertone() note = self._searchNote(note) out.preloader.setMessage("Loading note...") self.getEvernote().loadNoteContent(note) if raw: out.showNoteRaw(note) else: out.showNote(note) def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=None, note=None): result = { "title": title, "content": content, "tags": tags, "notebook": notebook, "resources": resources, } result = tools.strip(result) # if get note without params if note and title is None and content is None and tags is None and notebook is None: content = config.EDITOR_OPEN if title is None and note: result['title'] = note.title if content: if content != config.EDITOR_OPEN: if isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = Editor.textToENML(content) result['content'] = content if tags: result['tags'] = tools.strip(tags.split(',')) if notebook: notepadGuid = Notebooks().getNoteGUID(notebook) if notepadGuid is None: newNotepad = Notebooks().create(notebook) notepadGuid = newNotepad.guid result['notebook'] = notepadGuid logging.debug("Search notebook") return result def _searchNote(self, note): note = tools.strip(note) # load search result result = self.getStorage().getSearch() if result and tools.checkIsInt(note) and 1 <= int(note) <= len( result.notes): note = result.notes[int(note) - 1] else: request = self._createSearchRequest(search=note) logging.debug("Search notes: %s" % request) result = self.getEvernote().findNotes(request, 20) logging.debug("Search notes result: %s" % str(result)) if result.totalNotes == 0: out.failureMessage("Notes have not been found.") return tools.exitErr() elif result.totalNotes == 1 or self.selectFirstOnUpdate: note = result.notes[0] else: logging.debug("Choose notes: %s" % str(result.notes)) note = out.SelectSearchResult(result.notes) logging.debug("Selected note: %s" % str(note)) return note def find( self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None, with_url=None, count=None, ): request = self._createSearchRequest(search, tags, notebooks, date, exact_entry, content_search) if not count: count = 20 else: count = int(count) logging.debug("Search count: %s", count) createFilter = True if search == "*" else False result = self.getEvernote().findNotes(request, count, createFilter) # Reduces the count by the amount of notes already retrieved update_count = lambda c: max(c - len(result.notes), 0) count = update_count(count) # Evernote api will only return so many notes in one go. Checks for more # notes to come whilst obeying count rules while ((result.totalNotes != len(result.notes)) and count != 0): offset = len(result.notes) result.notes += self.getEvernote().findNotes( request, count, createFilter, offset).notes count = update_count(count) if result.totalNotes == 0: out.failureMessage("Notes have not been found.") return tools.exitErr() # save search result # print result self.getStorage().setSearch(result) out.SearchResult(result.notes, request, showUrl=with_url) def _createSearchRequest(self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None): request = "" if notebooks: for notebook in tools.strip(notebooks.split(',')): if notebook.startswith('-'): request += '-notebook:"%s" ' % tools.strip(notebook[1:]) else: request += 'notebook:"%s" ' % tools.strip(notebook) if tags: for tag in tools.strip(tags.split(',')): if tag.startswith('-'): request += '-tag:"%s" ' % tag[1:] else: request += 'tag:"%s" ' % tag if date: date = tools.strip(date.split('-')) try: dateStruct = time.strptime(date[0] + " 00:00:00", "%d.%m.%Y %H:%M:%S") request += 'created:%s ' % time.strftime( "%Y%m%d", time.localtime(time.mktime(dateStruct))) if len(date) == 2: dateStruct = time.strptime(date[1] + " 00:00:00", "%d.%m.%Y %H:%M:%S") request += '-created:%s ' % time.strftime( "%Y%m%d", time.localtime(time.mktime(dateStruct) + 60 * 60 * 24)) except ValueError, e: out.failureMessage( 'Incorrect date format in --date attribute. ' 'Format: %s' % time.strftime( "%d.%m.%Y", time.strptime('19991231', "%Y%m%d"))) return tools.exitErr() if search: search = tools.strip(search) if exact_entry or self.findExactOnUpdate: search = '"%s"' % search if content_search: request += "%s" % search else: request += "intitle:%s" % search logging.debug("Search request: %s", request) return request
def _get_notes(self): """ Get notes from evernote. """ keywords = 'notebook:"{0}"'.format(tools.strip(self.notebook_name)) return GeekNote().findNotes(keywords, 10000).notes
def _createSearchRequest(self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None, ignore_completed=None, reminders_only=None): request = "" def _formatExpression(label, value): """Create an expression like label:value, attending to negation and quotes """ expression = "" # if negated, prepend that to the expression before labe, not value if value.startswith('-'): expression += '-' value = value[1:] value = tools.strip(value) # values with spaces must be quoted if ' ' in value: value = '"%s"' % value expression += '%s:%s ' % (label, value) return expression if notebooks: for notebook in tools.strip(notebooks.split(',')): request += _formatExpression('notebook', notebook) if tags: for tag in tags: request += _formatExpression('tag', tag) if date: date = tools.strip(re.split(config.DEF_DATE_RANGE_DELIMITER, date)) # Timestamps used by the evernote service will always be in UTC, # per https://discussion.evernote.com/topic/18792-get-timestamp-in-local-time-zone/ # (user.timezone refers only to the UI and has no effect on the API) # Here we assume the user is specifying localized time, so we use _getTimeFromDate to # give us the UTC timestamp try: request += 'created:%s ' % time.strftime( "%Y%m%dT%H%M00Z", time.gmtime(self._getTimeFromDate(date[0]) / 1000)) if len(date) == 2: request += '-created:%s ' % time.strftime( "%Y%m%dT%H%M00Z", time.gmtime( self._getTimeFromDate(date[1]) / 1000 + 60 * 60 * 24)) except ValueError: out.failureMessage( 'Incorrect date format (%s) in --date attribute. ' 'Format: %s' % (date, time.strftime(config.DEF_DATE_FORMAT, time.strptime('20151231', "%Y%m%d")))) return tools.exitErr() if search: search = tools.strip(search) if exact_entry or self.findExactOnUpdate: search = '"%s"' % search if content_search: request += "%s" % search else: request += "intitle:%s" % search if reminders_only: request += ' reminderOrder:* ' if ignore_completed: request += ' -reminderDoneTime:* ' logging.debug("Search request: %s", request) return request
def _get_notes(self): """ Get notes from evernote. """ keywords = 'notebook:"{0}"'.format(tools.strip(self.notebook_name.encode('utf-8'))) return GeekNote(sleepOnRateLimit=self.sleep_on_ratelimit).findNotes(keywords, EDAM_USER_NOTES_MAX).notes
def _createSearchRequest( self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None, ignore_completed=None, reminders_only=None, ): request = "" def _formatExpression(label, value): """Create an expression like label:value, attending to negation and quotes """ expression = "" # if negated, prepend that to the expression before labe, not value if value.startswith("-"): expression += "-" value = value[1:] value = tools.strip(value) # values with spaces must be quoted if " " in value: value = '"%s"' % value expression += "%s:%s " % (label, value) return expression if notebooks: for notebook in tools.strip(notebooks.split(",")): request += _formatExpression("notebook", notebook) if tags: for tag in tools.strip(tags.split(",")): request += _formatExpression("tag", tag) if date: date = tools.strip(re.split(config.DEF_DATE_RANGE_DELIMITER, date)) try: dateStruct = time.strptime(date[0], config.DEF_DATE_FORMAT) request += "created:%s " % time.strftime("%Y%m%d", time.localtime(time.mktime(dateStruct))) if len(date) == 2: dateStruct = time.strptime(date[1], config.DEF_DATE_FORMAT) request += "-created:%s " % time.strftime( "%Y%m%d", time.localtime(time.mktime(dateStruct) + 60 * 60 * 24) ) except ValueError: out.failureMessage( "Incorrect date format (%s) in --date attribute. " "Format: %s" % (date, time.strftime(config.DEF_DATE_FORMAT, time.strptime("19991231", "%Y%m%d"))) ) return tools.exitErr() if search: search = tools.strip(search) if exact_entry or self.findExactOnUpdate: search = '"%s"' % search if content_search: request += "%s" % search else: request += "intitle:%s" % search if reminders_only: request += " reminderOrder:* " if ignore_completed: request += " -reminderDoneTime:* " logging.debug("Search request: %s", request) return request
def _createSearchRequest(self, search=None, tags=None, notebooks=None, date=None, exact_entry=None, content_search=None, ignore_completed=None, reminders_only=None): request = "" def _formatExpression(label, value): """Create an expression like label:value, attending to negation and quotes """ expression = "" # if negated, prepend that to the expression before labe, not value if value.startswith('-'): expression += '-' value = value[1:] value = tools.strip(value) # values with spaces must be quoted if ' ' in value: value = '"%s"' % value expression += '%s:%s ' % (label, value) return expression if notebooks: for notebook in tools.strip(notebooks.split(',')): request += _formatExpression('notebook', notebook) if tags: for tag in tools.strip(tags.split(',')): request += _formatExpression('tag', tag) if date: date = tools.strip(date.split('-')) try: dateStruct = time.strptime(date[0] + " 00:00:00", config.DEF_DATE_FORMAT) request += 'created:%s ' % time.strftime("%Y%m%d", time.localtime(time.mktime(dateStruct))) if len(date) == 2: dateStruct = time.strptime(date[1] + " 00:00:00", config.DEF_DATE_AND_TIME_FORMAT) request += '-created:%s ' % time.strftime("%Y%m%d", time.localtime(time.mktime(dateStruct) + 60 * 60 * 24)) except ValueError: out.failureMessage('Incorrect date format in --date attribute. ' 'Format: %s' % time.strftime(config.DEF_DATE_FORMAT, time.strptime('19991231', "%Y%m%d"))) return tools.exitErr() if search: search = tools.strip(search) if exact_entry or self.findExactOnUpdate: search = '"%s"' % search if content_search: request += "%s" % search else: request += "intitle:%s" % search if reminders_only: request += ' reminderOrder:* ' if ignore_completed: request += ' -reminderDoneTime:* ' logging.debug("Search request: %s", request) return request
def _parseInput(self, title=None, content=None, tags=[], created=None, notebook=None, resources=[], note=None, reminder=None, url=None): result = { "title": title, "content": content, "tags": tags, "created": created, "notebook": notebook, "resources": resources, "reminder": reminder, "url": url, } result = tools.strip(result) # if get note without params if (note and title is None and content is None and tags is None and created is None and notebook is None and resources is None and reminder is None and url is None): content = config.EDITOR_OPEN if title is None and note: result['title'] = note.title if content: if content != config.EDITOR_OPEN: if isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = Editor.textToENML(content) result['content'] = content if created: try: result['created'] = self._getTimeFromDate(created) except ValueError: out.failureMessage("Incorrect date format (%s) in --created attribute. 'Format: '%s' or '%s'" % (created, time.strftime(config.DEF_DATE_FORMAT, time.strptime('20151231', "%Y%m%d")), time.strftime(config.DEF_DATE_AND_TIME_FORMAT, time.strptime('201512311430', "%Y%m%d%H%M")))) return tools.exitErr() if notebook: notebookGuid = Notebooks()._getNotebookGUID(notebook) if notebookGuid is None: newNotebook = Notebooks().create(notebook) notebookGuid = newNotebook.guid result['notebook'] = notebookGuid logging.debug("Search notebook") if reminder: then = config.REMINDER_SHORTCUTS.get(reminder) if then: now = int(round(time.time() * 1000)) result['reminder'] = now + then elif reminder not in [config.REMINDER_NONE, config.REMINDER_DONE, config.REMINDER_DELETE]: try: result['reminder'] = self._getTimeFromDate(reminder) except ValueError: out.failureMessage("Incorrect date format (%s) in --reminder attribute. 'Format: '%s' or '%s'" % (reminder, time.strftime(config.DEF_DATE_FORMAT, time.strptime('20151231', "%Y%m%d")), time.strftime(config.DEF_DATE_AND_TIME_FORMAT, time.strptime('201512311430', "%Y%m%d%H%M")))) return tools.exitErr() if url is None and note: if note.attributes is not None: result['url'] = note.attributes.sourceURL return result
def _createSearchRequest(self, search=None, tags=None, notebook=None, date=None, exact_entry=None, content_search=None, ignore_completed=None, reminders_only=None): request = "" def _formatExpression(label, value): """Create an expression like label:value, attending to negation and quotes """ expression = "" # if negated, prepend that to the expression before labe, not value if value.startswith('-'): expression += '-' value = value[1:] value = tools.strip(value) # values with spaces must be quoted if ' ' in value: value = '"%s"' % value expression += '%s:%s ' % (label, value) return expression if notebook: request += _formatExpression('notebook', notebook) if tags: for tag in tags: request += _formatExpression('tag', tag) if date: date = tools.strip(re.split(config.DEF_DATE_RANGE_DELIMITER, date)) # Timestamps used by the evernote service will always be in UTC, # per https://discussion.evernote.com/topic/18792-get-timestamp-in-local-time-zone/ # (user.timezone refers only to the UI and has no effect on the API) # Here we assume the user is specifying localized time, so we use _getTimeFromDate to # give us the UTC timestamp try: request += 'created:%s ' % time.strftime("%Y%m%dT%H%M00Z", time.gmtime(self._getTimeFromDate(date[0])/1000)) if len(date) == 2: request += '-created:%s ' % time.strftime("%Y%m%dT%H%M00Z", time.gmtime(self._getTimeFromDate(date[1])/1000 + 60 * 60 * 24)) except ValueError: out.failureMessage('Incorrect date format (%s) in --date attribute. ' 'Format: %s' % (date, time.strftime(config.DEF_DATE_FORMAT, time.strptime('20151231', "%Y%m%d")))) return tools.exitErr() if search: search = tools.strip(search) if exact_entry or self.findExactOnUpdate: search = '"%s"' % search if content_search: request += "%s" % search else: request += "intitle:%s" % search if reminders_only: request += ' reminderOrder:* ' if ignore_completed: request += ' -reminderDoneTime:* ' logging.debug("Search request: %s", request) return request
def _parseInput( self, title=None, content=None, tags=None, created=None, notebook=None, resources=[], note=None, reminder=None ): result = { "title": title, "content": content, "tags": tags, "created": created, "notebook": notebook, "resources": resources, "reminder": reminder, } result = tools.strip(result) # if get note without params if ( note and title is None and content is None and tags is None and created is None and reminder is None and notebook is None ): content = config.EDITOR_OPEN if title is None and note: result["title"] = note.title if content: if content != config.EDITOR_OPEN: if isinstance(content, str) and os.path.isfile(content): logging.debug("Load content from the file") content = open(content, "r").read() logging.debug("Convert content") content = Editor.textToENML(content) result["content"] = content if tags: result["tags"] = tools.strip(tags.split(",")) if created: result["created"] = self._getTimeFromDate(created) if notebook: notepadGuid = Notebooks().getNoteGUID(notebook) if notepadGuid is None: newNotepad = Notebooks().create(notebook) notepadGuid = newNotepad.guid result["notebook"] = notepadGuid logging.debug("Search notebook") if reminder: then = config.REMINDER_SHORTCUTS.get(reminder) if then: now = int(round(time.time() * 1000)) result["reminder"] = now + then elif reminder not in [config.REMINDER_NONE, config.REMINDER_DONE, config.REMINDER_DELETE]: result["reminder"] = self._getTimeFromDate(reminder) return result