} 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 = {}
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( searchResultObject.id).get('value').get('format').get( 'page_icon')) else: searchResultObject.icon = None searchResultObject.title = searchResults.recordMap.get(
headers = {"Content-type": "application/json", "Cookie": cookie} conn = http.client.HTTPSConnection("www.notion.so") conn.request( "POST", "/api/v3/getRecentPageVisits", buildnotionrecentpagevisitsquery( bakedCookies.get("notion_user_id")), headers) response = conn.getresponse() data = response.read() conn.close() # Extract search results from notion recent page visits response searchResults = Payload(data) for x in searchResults.pages: searchResultObject = SearchResult(x.get('id')) searchResultObject.title = x.get('name') searchResultObject.subtitle = " " searchResultObject.icon = None if enableIcons: #check if there is an icon emoji or a fullIconUrl for the search result if "iconEmoji" in x: searchResultObject.icon = geticonpath( searchResultObject.id, x.get('iconEmoji')) if "fullIconUrl" in x: searchResultObject.icon = geticonpath( searchResultObject.id, x.get('fullIconUrl')) searchResultObject.link = getnotionurl( ) + searchResultObject.id.replace("-", "") searchResultList.append(searchResultObject) else: headers = {"Content-type": "application/json", "Cookie": cookie}