#!/usr/bin/env python # encoding: utf-8 from Alfred import Items, Tools from Notes import Notes, Search items = Items() notes = Notes() search = Search() zettel_id = Tools.getZettelId() query = Tools.getArgv(1) query_alt = u"{0} {1}".format(zettel_id, query) zettel_action = u"\u2318 Add Zettel ID" paste_action = u"\u2325 Paste clipboard" quicklook_action = u"\u21E7 Quicklook" if notes.useZettelId(): query_alt = query query = u"{0} {1}".format(zettel_id, query_alt) zettel_action = u"\u2318 Remove Zettel ID" items.setItem( arg=u"{0}||".format(query), subtitle=u"\"{0}\" ({1}, {2})".format(query, zettel_action, paste_action), title="Create note", ) items.addMod( arg=u"{0}||".format(query_alt), key="cmd", subtitle=u"\"{0}\" ({1})".format(query_alt, paste_action), )
def console_log(msg): # Create a custom logger logger = logging.getLogger(__name__) # Create handlers c_handler = logging.StreamHandler() c_handler.setLevel(logging.WARN) # Create formatters and add it to handlers c_format = logging.Formatter('%(message)s') c_handler.setFormatter(c_format) # Add handlers to the logger logger.addHandler(c_handler) logger.warn(msg) auth_token = Tools.getEnv('evernote_auth_token') f_path = Tools.getArgv(1) # f_path = '/Users/jjung/Documents/Notes/test evernote import.md' if auth_token == str(): Tools.notify('Evernote authentication error', 'Set Evernote AuthToken in worfklow configuration!') sys.exit("Error") elif f_path != str(): p = EvernoteUpload(auth_token) note_app_link = p.upload_to_notebook(f_path, 'Inbox') if note_app_link is not str(): Tools.notify('Upload in progress', 'The Note will be opened once uploaded!') sys.stdout.write(note_app_link) else: Tools.notify("Something went wrong")
def path_to_bookmarks(): user_dir = os.path.expanduser('~') bm = user_dir + BRAVE_BOOKMARKS bm_dev = user_dir + BRAVE_DEV_BOOKMARKS if os.path.isfile(bm): return bm elif os.path.isfile(bm_dev): return bm_dev def get_json_from_file(file): return json.load(codecs.open(file, 'r', 'utf-8-sig'))['roots'] wf = Items() query = Tools.getArgv(1) if Tools.getArgv(1) is not None else str() bookmarks_file = path_to_bookmarks() if bookmarks_file is not None: bm_json = get_json_from_file(bookmarks_file) bookmarks = get_all_urls(bm_json) for bm in bookmarks: name = bm.get('name') url = bm.get('url') if query == str() or query.lower() in name.lower(): wf.setItem(title=name, subtitle=url, arg=url, quicklookurl=url) wf.addItem() if wf.getItemsLengths() == 0: wf.setItem(title='No Bookmark found!', subtitle='Search \"%s\" in Google...' % query,
to_replace = ['/', '\\', ':', '|'] tmp = f.decode('utf-8').strip() for i in to_replace: tmp = tmp.replace(i, '-') return tmp.encode('utf-8') def writeMarkdown(md_content, md_path): with open(md_path, "w+") as f: f.write(md_content.encode('utf-8')) mn = MyNotes.Search() ext = mn.getNotesExtension() p = mn.getNotesPath() argv = Tools.getArgv(1) url = argv if argv.startswith( 'http://') or argv.startswith('https://') else str() # TODO: When HTML is not fetchable, the URL will be used. # Fix formatting from <url> to markdown url [title](url) if url: markdown = Markdown(url) today = markdown.getTodayDate(fmt="%d.%m.%Y") today_time = markdown.getTodayDate(fmt="%d-%m-%Y %H-%M") md = markdown.getMarkdownContent() file_name = parseFilename(markdown.getTitle()) if file_name == str(): file_name = Tools.strJoin('WebClip from ', today_time) fPath = mn.strJoin(p, file_name, ext)
import json import os import sys from Alfred import Tools wf_data_dir = Tools.getDataDir() config_file = os.path.join(wf_data_dir, 'folders.json') if os.path.isfile(config_file): with open(config_file, "r") as f: config = json.load(f) else: config = dict() query = Tools.getArgv(1).split('|') if len(query) > 1: target_dir = query[0] action = query[1] else: target_dir = query[0] action = "ADD" target_name = os.path.basename(target_dir) if action == "ADD": config.update({target_name: target_dir}) else: new_config = dict() for k, v in config.items(): if k != target_name:
#!/usr/bin/env python # encoding: utf-8 from Alfred import Tools from Notes import Note, Search from QuerySplitter import QuerySplitter import sys reload(sys) sys.setdefaultencoding('utf-8') query = Tools.getArgv(1).encode('utf-8') clipboard = Tools.getEnv('clipboard') template = Tools.getEnv('template') paste = Tools.getEnv('paste') qs = QuerySplitter(query) if query: note = Note( content=str() if not paste else clipboard, tags=qs.tags, template_path=template, title=qs.title, zettel_id=qs.zettel_id, ) file_path = note.createNote() output = Search().getNoteFilename(file_path) sys.stdout.write(output)
def copyFile(source, target_dir): file_name = str() if os.path.isfile(source): file_name = os.path.basename(source) valid_file_name = re.sub('[^\w_.)(-]', '_', file_name) destination = os.path.join(target_dir, valid_file_name) copy2(source, destination) file_name = valid_file_name else: raise ValueError return os.path.join(target_dir, file_name) def getMediaFolder(): notes_path = Tools.getNotesPath() media_dir = Tools.settings('resourcesSubfolder', 'media') media_path = os.path.join(notes_path, media_dir) if not (os.path.exists(media_path)): os.mkdir(media_path) return media_path source_file = Tools.getArgv(1) target_dir = getMediaFolder() image_file = copyFile(source_file, target_dir) file_url = urllib.pathname2url(image_file) link = '![{0}]({1})'.format(os.path.basename(image_file), file_url) sys.stdout.write(link)
newList.append(i) else: newList = li return newList[:50] def path_to_history(): user_dir = os.path.expanduser('~') bm = user_dir + BRAVE_HISTORY bm_dev = user_dir + BRAVE_DEV_HISTORY return bm if os.path.isfile(bm) else bm_dev wf = Items() search_term = Tools.getArgv(1) if Tools.getArgv(1) is not None else '' chrome_locked_db = path_to_history() history_db = '/tmp/History' try: shutil.copy2(chrome_locked_db, '/tmp') except IOError: wf.setItem(title="Brave Browser History not found!", subtitle="You may use an older version of Brave or no Brave", valid=False) wf.addItem() wf.write() exit() with sqlite3.connect(history_db) as c: cursor = c.cursor()