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

【已解决】支持通过配置对于单个印象笔记的帖子直接先同步再上传到WordPress

WordPress crifan 455浏览 0评论
折腾:
【未解决】Python处理发布印象笔记帖子到WordPress后的部分细节优化
期间,调试时发现:
每次想要调试单个帖子时,
只能先去调试同步:processNoteCallback
调试完毕后,停止调试,把evernote的process从True改为False,再去调试:uploadNoteCallback
即对于目前的帖子:
没法对于单个帖子,直接先sync后再upload,不太方便。
所以此处,打算去加上调试配置,允许2种模式:
  • 批量模式
    • 对于1_ToProcess目录先全部批量的sync
    • 再针对于2_ToUpload全部批量的upload
  • 单个帖子模式
    • 对于1_ToProcess目录的单个帖子,先sync后(根据配置也会移动到2_ToUpload),再upload该帖子
    • 再对于2_ToUpload中的帖子,去upload

去改造代码
先定义好2种模式:
from enum import Enum

class ProcessMode(Enum):
    SINGLE = 1 # for single note: sync+upload
    BATCH = 2 # for process folder, batch sync; for upload folder, batch upload


gCfg = {
    "mode": ProcessMode.SINGLE,
    "evernote": {
。。。
然后去改造逻辑
EvernoteToWordpress.py
def processAndUploadCallback(curNote):
    # 1. sync
    processNoteCallback(curNote)
    # 2. upload
    noteDetail = gEvernote.getNoteDetail(curNote.guid)
    uploadNoteCallback(noteDetail)

def EvernoteToWordpress():
    """Process evernote note into wordpress

    Args:
    Returns:
    Raises:
    """
    global gCfg

    # sync
    if gCfg["evernote"]["process"]["enable"]:
        toProcessNotebook = gCfg["evernote"]["process"]["notebook"]
        toProcessNotebookGuid = toProcessNotebook["guid"]
        if gCfg["mode"] == ProcessMode.SINGLE:
            processSingleNotebook(toProcessNotebookGuid, processAndUploadCallback)
        else:
            processSingleNotebook(toProcessNotebookGuid, processNoteCallback)

    # upload
    if gCfg["evernote"]["upload"]["enable"]:
        toUploadNotebook = gCfg["evernote"]["upload"]["notebook"]
        toUploadNotebookGuid = toUploadNotebook["guid"]
        processSingleNotebook(toUploadNotebookGuid, uploadNoteCallback)
去调试看看
是可以的:
把帖子:
【已解决】水之道苏州清源华衍水务关注公众号和绑定户号
实现了我们的效果:
  • 从1_ToProcess sync到了2_ToUpload
  • 再从2_ToUpload upload到了3_Published
即可。
【总结】
此处最后代码是:
    SINGLE = 1 # for single note: sync+upload
    BATCH = 2 # for process folder, batch sync; for upload folder, batch upload

gCfg = {
    "mode": ProcessMode.SINGLE,
。。。

def EvernoteToWordpress():
。。。

    if gCfg["evernote"]["process"]["enable"]:
        toProcessNotebook = gCfg["evernote"]["process"]["notebook"]
        toProcessNotebookGuid = toProcessNotebook["guid"]
        if gCfg["mode"] == ProcessMode.SINGLE:
            processSingleNotebook(toProcessNotebookGuid, processAndUploadCallback)
        else:
            processSingleNotebook(toProcessNotebookGuid, processNoteCallback)


    # upload
    if gCfg["evernote"]["upload"]["enable"]:
        toUploadNotebook = gCfg["evernote"]["upload"]["notebook"]
        toUploadNotebookGuid = toUploadNotebook["guid"]
        processSingleNotebook(toUploadNotebookGuid, uploadNoteCallback)
实现了:
当single模式时,处理1_ToProcess的帖子,是一次性的 sync+upload的效果。

转载请注明:在路上 » 【已解决】支持通过配置对于单个印象笔记的帖子直接先同步再上传到WordPress

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.187 seconds, using 23.34MB memory