#!/usr/bin/python # -*- coding: utf-8 -*- from Alfred import Items, Tools from MyNotes import Search query = Tools.getArgv(1) bmt = Tools.getEnv('bookmark_tag') bookmark_tag = bmt if bmt.startswith('#') else '#' + bmt search_terms = '{0}&{1}'.format(bookmark_tag, query) if query else bookmark_tag notes = Search() search_terms, _ = notes.get_search_config(search_terms) matches = notes.url_search(search_terms) alf = Items() if matches: for m in matches: note_title = m.get('title') note_path = m.get('path') links = m.get('links') for l in links: url_title = l.get('url_title') url = l.get('url') # subtitle = '%s > %s' % (url_title, url) if url_title != url else url subtitle = 'NOTE: {0} URL: {1}...'.format(note_title, url[:30]) alf.setItem( title=url_title, subtitle=subtitle, arg=url,
from Alfred import Items as Items from Alfred import Tools as Tools from MyNotes import Search # create MD search object md_search = Search() # Load Env variables query = Tools.getArgv(1) # TODO: For testing, delete 3 lines #query = "Äsch".encode('utf-8') # sys.stderr.write(query) # Get Search config with AND and OR search_terms, search_type = md_search.get_search_config(query) # create WF object wf = Items() # exec search if search terms were entered if len(search_terms) > 0: sorted_file_list = md_search.notes_search(search_terms, search_type) # get full list of file in case no search was entered else: sorted_file_list = md_search.getFilesListSorted() # Write search results into WF object for f in sorted_file_list: c_date = Tools.getDateStr(f['ctime']) m_date = Tools.getDateStr(f['mtime']) wf.setItem(