最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Python获取印象笔记的帖子的标签名称列表

Python crifan 389浏览 0评论
折腾:
【已解决】给Python发布印象笔记帖子内容到WordPress文章时加上分类和标签
期间,先要去获取到当前印象笔记Evernote的Note笔记的tag标签的列表。
主要是获取到tag的name的list。
从印象笔记中获取当前帖子的标签列表
去写代码看看
对于:
Mac,pmset,GPU,显卡模式,切换
去调试看看获取到的值如何
获取到的是
curNote.tagGuids = ['1dda873b-310e-46be-b...a1f8c95720', '6ff65876-aab4-406b-b...1105638450', '38f11450-1a7a-4f54-b...8889c1567a', '46258420-3d2e-443c-b...431e061aab', '52b7babc-d6ea-4390-b...c21da5188e']
所以需要继续去:从guid获取到tag
去找资料
Function: NoteStore.getTag
Types.Tag getTag(string authenticationToken,
                 Types.Guid guid)
    throws Errors.EDAMUserException, Errors.EDAMSystemException, Errors.EDAMNotFoundException
”Returns the current state of the Tag with the provided GUID.
@param  guid The GUID of the tag to be retrieved.
@throws  EDAMUserException
* BAD_DATA_FORMAT “Tag.guid” – if the parameter is missing
* PERMISSION_DENIED “Tag” – private Tag, user doesn’t own
@throws  EDAMNotFoundException
* “Tag.guid” – tag not found, by GUID
去试试
其中关于tag的属性,参考
Struct: Tag
Field
Type
guid
name
string
parentGuid
updateSequenceNum
i32
A tag within a user’s account is a unique name which may be organized a simple hierarchy.
guid
The unique identifier of this tag. Will be set by the service, so may be omitted by the client when creating the Tag.
Length: EDAM_GUID_LEN_MIN – EDAM_GUID_LEN_MAX
Regex: EDAM_GUID_REGEX
name
A sequence of characters representing the tag’s identifier. Case is preserved, but is ignored for comparisons. This means that an account may only have one tag with a given name, via case-insensitive comparison, so an account may not have both “food” and “Food” tags. May not contain a comma (‘,’), and may not begin or end with a space.
Length: EDAM_TAG_NAME_LEN_MIN – EDAM_TAG_NAME_LEN_MAX
Regex: EDAM_TAG_NAME_REGEX
parentGuid
If this is set, then this is the GUID of the tag that holds this tag within the tag organizational hierarchy. If this is not set, then the tag has no parent and it is a “top level” tag. Cycles are not allowed (e.g. a->parent->parent == a) and will be rejected by the service.
Length: EDAM_GUID_LEN_MIN – EDAM_GUID_LEN_MAX
Regex: EDAM_GUID_REGEX
updateSequenceNum
A number identifying the last transaction to modify the state of this object. The USN values are sequential within an account, and can be used to compare the order of modifications within the service.
继续写代码
        tagGuidList = curNote.tagGuids
        logging.debug("tagGuidList=%s", tagGuidList)
        for eachTagGuid in tagGuidList:
            tagInfo = self.evernote.noteStore.getTag(eachTagGuid)
            logging.debug("tagInfo=%s", tagInfo)
可以获取tag的name了:
输出:
20201201 09:44:24 crifanEvernoteToWordpress.py:183  INFO    curTagList=['Mac', '切换', 'GPU', 'pmset', '显卡模式']
是我们希望的,保留原始tag的顺序。
【总结】
最后用代码:
libs/crifan/crifanEvernote.py
    def getTagNameList(self, curNote):
        """get note tag name list

        Args:
            curNote (Note): Evernote Note
        Returns:
            tag name list(list)
        Raises:
        """
        curTagList = []
        tagGuidList = curNote.tagGuids
        logging.debug("tagGuidList=%s", tagGuidList)
        # tagGuidList=['1dda873b-310e-46be-b59e-02a1f8c95720', '6ff65876-aab4-406b-b52b-4c1105638450', '38f11450-1a7a-4f54-ba17-b78889c1567a', '46258420-3d2e-443c-b63d-c5431e061aab', '52b7babc-d6ea-4390-b405-79c21da5188e']
        for eachTagGuid in tagGuidList:
            tagInfo = self.noteStore.getTag(eachTagGuid)
            logging.debug("tagInfo=%s", tagInfo)
            curTagStr = tagInfo.name
            curTagList.append(curTagStr)
        logging.info("curTagList=%s", curTagList)
        # curTagList=['Mac', '切换', 'GPU', 'pmset', '显卡模式']
        return curTagList
即可获取当前帖子的标签的名称列表。
最新代码详见:
https://github.com/crifan/crifanLibPython/blob/master/crifanLib/crifanEvernote.py

转载请注明:在路上 » 【已解决】Python获取印象笔记的帖子的标签名称列表

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.204 seconds, using 23.36MB memory