예제 #1
0
TITLE_REPLACE_PATTERN = "<em>(.*)</em>"

# Extract search results from lark response
searchResultList = []
objs = data['entities']['objs']
for k in data['tokens']:
    obj = objs[k]
    searchResultObject = SearchResult(obj['token'])
    title = obj['title']
    title = re.sub(TITLE_REPLACE_PATTERN, r"\1", title)
    searchResultObject.title = title
    viewed_time = datetime.fromtimestamp(obj['open_time']).strftime('%H:%M')
    updated_time = datetime.fromtimestamp(obj['edit_time']).isoformat()
    searchResultObject.subtitle = "Author: " + obj['author'] + ", You viewed " + viewed_time + ", " + obj['edit_name'] + " updated " + updated_time
    searchResultObject.link = obj['url']
    if ITEM_TYPE_ICONNAME_MAPPING.has_key(obj['type']):
        searchResultObject.icon = "itemicons/" + ITEM_TYPE_ICONNAME_MAPPING.get(obj['type'])
    searchResultList.append(searchResultObject)

itemList = []
for searchResultObject in searchResultList:
    item = {}
    item["uid"] = searchResultObject.id
    item["type"] = "default"
    item["title"] = searchResultObject.title
    item["arg"] = searchResultObject.link
    item["subtitle"] = searchResultObject.subtitle
    if searchResultObject.icon:
        icon = {}
        icon["path"] = searchResultObject.icon
예제 #2
0
            searchResultObject.id).get('value'):
        if "page_icon" in searchResults.recordMap.get('block').get(
                searchResultObject.id).get('value').get('format'):
            if enableIcons:
                searchResultObject.icon = geticonpath(
                    searchResultObject.id,
                    searchResults.recordMap.get('block').get(
                        searchResultObject.id).get('value').get('format').get(
                            'page_icon'))
            else:
                searchResultObject.icon = None
                searchResultObject.title = searchResults.recordMap.get(
                    'block').get(
                        searchResultObject.id).get('value').get('format').get(
                            'page_icon') + " " + searchResultObject.title
    searchResultObject.link = getnotionurl() + searchResultObject.id.replace(
        "-", "")
    searchResultList.append(searchResultObject)

itemList = []
for searchResultObject in searchResultList:
    item = {}
    item["uid"] = searchResultObject.id
    item["type"] = "default"
    item["title"] = searchResultObject.title
    item["arg"] = searchResultObject.link
    item["subtitle"] = searchResultObject.subtitle
    if searchResultObject.icon:
        icon = {}
        icon["path"] = searchResultObject.icon
        item["icon"] = icon
    item["autocomplete"] = searchResultObject.title
    title = obj['title']
    title = re.sub(TITLE_REPLACE_PATTERN, r"\1", title)
    searchResultObject.title = title
    viewed_time = datetime.fromtimestamp(obj['open_time']).strftime('%H:%M')
    updated_time = datetime.fromtimestamp(obj['edit_time']).isoformat()
    searchResultObject.subtitle = "Author: " + obj[
        'author'] + ", You viewed " + viewed_time + ", " + obj[
            'edit_name'] + " updated " + updated_time
    url = obj['url']
    if url:
        pass
    else:
        if obj['wiki_infos'] and len(obj['wiki_infos']):
            url = obj['wiki_infos'][0]['wiki_url']

    searchResultObject.link = url

    if ITEM_TYPE_ICONNAME_MAPPING.has_key(obj['type']):
        searchResultObject.icon = "itemicons/" + ITEM_TYPE_ICONNAME_MAPPING.get(
            obj['type'])
    searchResultList.append(searchResultObject)

itemList = []
for searchResultObject in searchResultList:
    item = {}
    item["uid"] = searchResultObject.id
    item["type"] = "default"
    item["title"] = searchResultObject.title
    item["arg"] = searchResultObject.link
    item["subtitle"] = searchResultObject.subtitle
    if searchResultObject.icon: