Jump to content

EdwinW

Member
  • Posts

    7
  • Joined

  • Last visited

Posts posted by EdwinW

  1. This is the address of the project : https://github.com/huamang/SiYuan-Search-workflow

     

    This is the specific log of debug

    [16:04:23.260] SiYuan[Script Filter] Queuing argument 's'
    [16:04:23.384] SiYuan[Script Filter] Script with argv '(null)' finished
    [16:04:23.389] ERROR: SiYuan[Script Filter] Code 1: Traceback (most recent call last):
      File "/Users/edwinwang/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.A73C9D10-C775-4B59-9699-E72DE2DBFE81/search.py", line 57, in <module>
        main()
      File "/Users/edwinwang/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.A73C9D10-C775-4B59-9699-E72DE2DBFE81/search.py", line 53, in main
        parseRes(resJson)
      File "/Users/edwinwang/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.A73C9D10-C775-4B59-9699-E72DE2DBFE81/search.py", line 37, in parseRes
        for block in resJson["data"]["blocks"]:
    KeyError: 'data'

     

    This is the specific content of the script

    import json
    import sys
    import requests
    
    def fullTextSearchBlock(q):
    searchJson = {}
    searchJson["query"] = q
    searchJson["method"] = 0
    type = {}
    type["blockquote"] = True
    type["codeBlock"] = True
    type["document"] = True
    type["embedBlock"] = True
    type["heading"] = True
    type["htmlBlock"] = True
    type["list"] = True
    type["listItem"] = True
    type["mathBlock"] = True
    type["paragraph"] = True
    type["superBlock"] = True
    type["table"] = True
    searchJson["type"] = type
    searchJson["path"] = []
    searchJson["groupBy"] = 0
    searchJson["orderBy"] = 0
    
    data = json.dumps(searchJson)
    url = "http://127.0.0.1:6806/api/search/fullTextSearchBlock"
    res = requests.post(url, data)
    resJson = json.loads(res.text)
    return resJson
    
    def parseRes(resJson):
    itemList = []
    uid = 1
    for block in resJson["data"]["blocks"]:
    item = {}
    item["uid"] = uid
    item["title"] = block["content"].replace("<mark>", "").replace("</mark>", "")[:50]
    item["subtitle"] = block["hPath"]
    item["arg"] = "siyuan://blocks/" + block["id"]
    itemList.append(item)
    uid += 1
    items = {}
    items["items"] = itemList
    items_json = json.dumps(items)
    sys.stdout.write(items_json)
    
    def main():
    alfredQuery = str(sys.argv[1])
    resJson = fullTextSearchBlock(alfredQuery)
    parseRes(resJson)
    
    if __name__ == '__main__':
    main()
×
×
  • Create New...