def save_document(content, reldir, filename): import editor # EDITORIAL module absdir = get_abspath(reldir) if not os.path.exists(absdir): os.makedirs(absdir) editor.set_file_contents(os.path.join(reldir, filename.replace('/','_')), content.encode('utf-8') if content else '')
def save_document(content, reldir, filename): # noinspection PyUnresolvedReferences import editor # EDITORIAL module absdir = get_abspath(reldir) if not os.path.exists(absdir): os.makedirs(absdir) editor.set_file_contents(os.path.join(reldir, filename.replace('/', '_')), content.encode('utf-8') if content else '')
def save_action(self, sender): if self.image_view.image: # We draw a new image here, so that it has the current # orientation (the canvas is quadratic). filename = time.strftime('%Y%m%d%H%M%S') + '.png' with ui.ImageContext(self.width, self.height) as ctx: self.image_view.image.draw() img = ctx.get_image() img = ui2pil(img) bbox = img.getbbox() img = img.crop(bbox) editor.set_file_contents(filename, img._repr_png_(), 'dropbox') editor.insert_text('![test](../' + filename + ')') self.close() else: console.hud_alert('No Image', 'error') workflow.set_output('test')
#coding: utf-8 import workflow import editor import clipboard import datetime entry_file = workflow.get_variable('entry_filename') file_contents = editor.get_file_contents(entry_file) if (file_contents): entry = file_contents else: entry = 'empty' daily_stats = workflow.get_variable('journal_stats') print('daily_stats' + daily_stats) editor.set_file_contents(filename, entry + '\n\n' + daily_stats) workflow.set_variable('entry_text', content) workflow.set_variable('entry_filename', filename) clipboard.set(content) workflow.set_output(content)
#coding: utf-8 import workflow import editor import clipboard import datetime raw_entry = workflow.get_variable('entry_text') entry_name = 'Journal 0{:%Y-%m-%d}'.format(datetime.date.today()) content = '# ' + entry_name + '\n\n' + raw_entry content = content.strip() + '\n' filename = entry_name + '.markdown' # daily_stats = workflow.get_variable('journal_stats') editor.set_file_contents(filename, content) #editor.set_file_contents(filename, content + '\n\n' + daily_stats) workflow.set_variable('entry_text', content) workflow.set_variable('entry_filename', filename) clipboard.set(content) workflow.set_output(content)
# coding: utf-8 # [Capitalize Workflow - Run Python Code](https://forum.omz-software.com/topic/2421/return-ticket-from-editorial-to-texttool-back-to-editorial) import workflow import editor import os action_in = workflow.get_input() #TODO: Generate the output... action_out = action_in path = editor.get_path() p, file_name = os.path.split(path) doc_drop = os.path.split(p)[1] data = editor.get_file_contents(file_name, doc_drop).split(". ") print data print[x.capitalize() for x in data] editor.set_file_contents(file_name, ". ".join([x.capitalize() for x in data]), doc_drop) editor.reload_files() workflow.set_output(action_out)
elif exif[orientation] == 8: img = image.rotate(90, expand=True) # cases: image don't have getexif except (AttributeError, KeyError, IndexError): pass doc_path = editor.get_path() doc_dir, fn = os.path.split(doc_path) default_name = '%s' % timestr + '_' + 'image' i = 1 while True: if not os.path.exists(os.path.join(doc_dir, default_name + '.jpg')): break default_name = '%s' % timestr + '_' + 'image' + '_' + str(i) i += 1 root, rel_doc_path = editor.to_relative_path(editor.get_path()) filename = default_name + '.jpg' if not filename: workflow.stop() img_data = io.BytesIO() img.save(img_data, 'jpeg') rel_doc_dir, fn = os.path.split(rel_doc_path) dest_path = os.path.join(rel_doc_dir, filename) editor.set_file_contents(dest_path, img_data.getvalue(), root) workflow.set_output(filename)
#coding: utf-8 # this file is for the editorial app (ios) workflow to send a markdown here to convert to pdf. import editor, requests, workflow HEROKU = "SECRET" # yeah this is crappy security but who cares? worst case scenario you HAXOR MY PANDOC INSTALLATION 1337 PWNAGE!!! target = "https://" + HEROKU + "/mdpdf" # this comes from workflow actions "get current file name" and then "set variable" (Input to "filename") filename = workflow.get_variable("filename") + ".pdf" markdown = editor.get_text(True) data = {"filename": filename, "markdown": markdown} response = requests.post(target, data=data) pdf = response.content editor.set_file_contents(filename, pdf, 'dropbox') print('done!') workflow.stop()
if rot_degrees: img = img.rotate(rot_degrees, expand=True) # cases: image don't have getexif except (AttributeError, KeyError, IndexError): pass doc_path = editor.get_path() doc_dir, fn = os.path.split(doc_path) default_name = '{}_image'.format(timestr) i = 1 while True: if not os.path.exists(os.path.join(doc_dir, default_name + '.jpg')): break default_name = '{}_image_{}'.format(timestr, i) i += 1 root, rel_doc_path = editor.to_relative_path(editor.get_path()) filename = default_name + '.jpg' if not filename: workflow.stop() img_data = io.BytesIO() img.save(img_data, 'jpeg') rel_doc_dir, fn = os.path.split(rel_doc_path) dest_path = os.path.join(rel_doc_dir, filename) editor.set_file_contents(dest_path, img_data.getvalue(), root) workflow.set_output(filename)