예제 #1
0
 def read(self, note_id):
     tempnote = self._notestore.getNote(self._token, note_id, True, False, False, False)     #Retreieve the note
     
     #Get the name of the notebook
     tempbook = EvernoteNotebook.objects.filter(user=self._user, id__exact=tempnote.notebookGuid).first() #Try to retreive the notebook name from the database
     if tempbook:
         notebookName = tempbook.name
     else:
         notebook = self._notestore.getNotebook(self._token, tempnote.notebookGuid)              #Get the name of the notebook of the note if not in database
         storeBook = EvernoteNotebook(user=self._user, id=tempnote.notebookGuid, name=notebook.name)
         storeBook.save()                                                                        #Save the notebook to the databse
         notebookName = notebook.name
         
     #Get the names of the tags of the note
     tags = []
     
     if tempnote.tagGuids:           #If there are any tags, add their guids to the list
         serverTags = None
         for tagid in tempnote.tagGuids:
             temptag = EvernoteTag.objects.filter(user=self._user, id__exact=tagid).first()
             if not temptag:
                 if serverTags == None:
                         serverTags = self._notestore.listTags(self._token)                  #Retreive list of tags on evernote servers if we don't already have it
                         
                 foundTag = [x for x in serverTags if x.guid == tagid]     #Find the tag with the correct guid
                 
                 if foundTag:
                         storeTag = EvernoteTag(user=self._user, id=foundTag[0].guid, name=foundTag[0].name)   #Add the to the database if we found it
                         storeTag.save()
                         
                         tags.append({'tag': storeTag.name, 'id': storeTag.id})
                 else:
                     #Error didnt find tag on server but should be there
                     tags.append(("ERRORFINDINGTAGNAME", tagid))
             else:
                 tags.append({'tag': temptag.name, 'id': temptag.id})
         
     #Strip the evernote specific metadata and tags from the content
     content = tempnote.content
     prefix1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
     prefix2 = "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
     prefix3 = "<en-note>"
     suffix1 = "</en-note>"
     
     x = content.find(prefix1)
     if not x == -1: content = content.split(prefix1)[1]
     x = content.find(prefix2)
     if not x == -1: content = content.split(prefix2)[1]
     x = content.find(prefix3)
     if not x == -1: content = content.split(prefix3)[1]
     x = content.rfind(suffix1)
     if not x == -1: content = content.rsplit(suffix1)[0]   
     
     note = Note(tempnote.title, content, notebookName, tempnote.notebookGuid, tags)       #, tempnote.attributes.reminderDoneTime, tempnote.attributes.reminderTime)
     return note
예제 #2
0
 def _getTagIdList(self, note):
     tags = []
     serverTags = None
     for tag in note.content['tags']:
         if tag.get('id'):              #Add the tag id to the list if we have it
             tags.append(tag.get('id'))
         else:                               
             temptag = EvernoteTag.objects.filter(user=self._user, name__iexact=tag['tag']).first()   #If we don't have, check for it in database
             if temptag:
                 tags.append(temptag.id)
             else:                                   #If not in database check if it is on evernote servers                    
                 if serverTags == None:
                     serverTags = self._notestore.listTags(self._token)         #Retreive list of tags on evernote servers if we don't already have it
                 
                 foundTag = [x for x in serverTags if x.name.lower() == tag['tag'].lower()]     #Find the tag with the correct name
                 
                 if foundTag:
                     storeTag = EvernoteTag(user=self._user, id=foundTag[0].guid, name=foundTag[0].name)   #Add the to the database if we found it
                     storeTag.save()
                     
                     tags.append(foundTag[0].guid)
                 else:
                     newTag = Types.Tag()                                            #Create the tag if it didn't exist on the server
                     newTag.name = tag['tag']
                     createdTag = self._notestore.createTag(self._token, newTag)
                     
                     storeTag = EvernoteTag(user=self._user, id=createdTag.guid, name=createdTag.name)   #And add it to the database
                     storeTag.save()
                     
                     tags.append(createdTag.guid)
     return tags