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")
assetfile_links = getAssetsLinks(parent, file_path) is_assetfile_deleted = False for l in assetfile_links: # Avoid Markdown file removal if not (l.endswith(ext)): is_assetfile_deleted = rmFile(l) # Delete Assets Folder remove_ext = len(ext) assets_path = Tools.strJoin(file_path[:-remove_ext], ".assets") assets_path_legacy = Tools.strJoin(file_path[:-remove_ext]) is_asset_deleted = rmDir(assets_path) or rmDir( assets_path_legacy) or is_assetfile_deleted # Finally delete the MD File is_file_deleted = rmFile(file_path) # Create Notification Message if len(files_to_delete) == 1: return_text = '- MD Note DELETED' if is_file_deleted else "Cannot delete file: {0}".format( file_name) return_text += '\n- Assets DELETED' if is_asset_deleted else str() if len(files_to_delete) > 1: return_text = "{0} Notes and coresponding Assets deleted".format( len(files_to_delete)) Tools.notify('MD Note deleted!', return_text) sys.stdout.write(last_query)
def writeMarkdown(md_content, md_path): with open(md_path, "w+") as f: f.write(md_content.encode('utf-8')) # f.write(md_content) mn = 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: Tools.notify('Fetch URL...', 'The Note will be opened after the import...') 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) # TODO: Remove # fPath = mn.strJoin(p, file_name, ext) fPath = os.path.join(p, "{0}{1}".format(file_name, ext)) writeMarkdown(md, fPath) sys.stdout.write(fPath)