data = response.read() data = data.replace("<gzkNfoUU>", "") data = data.replace("</gzkNfoUU>", "") conn.close() # Extract search results from notion response searchResultList = [] searchResults = Payload(data) for x in searchResults.results: searchResultObject = SearchResult(x.get('id')) if "properties" in searchResults.recordMap.get('block').get( searchResultObject.id).get('value'): searchResultObject.title = \ searchResults.recordMap.get('block').get(searchResultObject.id).get('value').get('properties').get('title')[ 0][0] else: searchResultObject.title = x.get('highlight').get('text') if "pathText" in x.get('highlight'): searchResultObject.subtitle = x.get('highlight').get('pathText') else: searchResultObject.subtitle = " " if "format" in searchResults.recordMap.get('block').get( 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(
ITEM_TYPE_ICONNAME_MAPPING = { 2: 'doc.png', 3: 'sheet.png', } 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