Editorial Workflows

Blogging with Ghost

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Several actions for blogging with Ghost (http://ghost.org)

Uses the current document to post, update or fetch existing entries. This workflow covers:

Upload new post - Create new post of the current document. First line is taken as title (leading # removed).

Update post - Update post with content of current document.

Upload image - Upload image and place markdown with url at cursor position.

List posts - Place CSV-styled list of all posts at cursor position

Fetch single post - Place content of single post at cursor position.

Fetch all posts - Place content of all posts at cursor position.

Delete post - Delete a post.

Get settings - Place settings at cursor position.


**Set blog url, username and password within the first three actions of the workflow.**
If using Ghost Pro, use https.

Ghost is in its early days and might undergo heavy changes. Tested with version 0.5. Might not work with future versions of Ghost and does definitely not work with earlier ones.

This workflow fits my own needs, not necessarily yours. Feel free to reuse parts of the workflow to build your own or adapt it to your needs.

Feel also free to report bugs although I don't promise any support.

Version 1.0.1

Shared by: @eidecker

Comments: Comment Feed (RSS)

jakubowiak — 02 Jan 2015
It seems that Ghost 0.5.7 API doesn't support "tags" property for a fetched posted. Because of that the "update post" function of your workflow doesn't work. I needed to comment all lines in the script to make it working. Any ideas how to make it work again?

+ Add Comment

Workflow Preview
Define Blog URL ?
Variable Name
url
Value
http://yourdomain.com
Define username ?
Variable Name
username
Value
Define password ?
Variable Name
password
Value
Check Settings ?
Run the block if
url
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
http://yourdomain.com
Show Alert ?
Title
Check Settings!
Message
Set blog url, username and password. To do this open workflow for modification (i), choose 'Edit Workflow...' and define the properties in the first three actions.
Button 1
Cancel
Output Value
Input
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
OFF
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
Show Alert ?
Title
Safety Warning
Message
WARNING: This workflow may alter or DELETE data on your Ghost blog and your device. It might have errors. It might do things you don't expect. Proceed at your own risk.
Button 1
OK
Output Value
Input
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Sanitize Blog URL ?
Source Code
#coding: utf-8
import workflow

# Append '/ghost/' to the url if not present
# so we can take this as given when accessing the api and 
# don't have to ask the user to do it, which would lead
# to confusion and errors

action_in = workflow.get_input()

url = workflow.get_variable('url')
url.strip()

if not(url.endswith('/')):
	url = url + '/'

if not(url.endswith('/ghost/')):
	url = url + ('ghost/')
	
workflow.set_variable('url', url)

action_out = action_in
workflow.set_output(action_out)
Choose action ?
Title
What do you want to do?
List (Lines)
Upload new post Update post Upload image and insert url Delete post Fetch single post Fetch all posts List posts Get settings
Multiple Selection
OFF
Show in Popover
OFF
Set Variable action ?
Variable Name
action
Value
Input
Get OAuth Token ?
Source Code
#coding: utf-8
import workflow
import requests
import json
import console

# Get OAuth-Token, client_id has to be 'ghost-admin'
postdata = {'grant_type': 'password',
             'username': workflow.get_variable('username'),
             'password' : workflow.get_variable('password'),
             'client_id' : 'ghost-admin'}
             
headers = {'Content-Type': 'application/x-www-form-urlencoded'}

try:
	response = requests.post(workflow.get_variable('url') + 'api/v0.1/authentication/token/', data=postdata, headers=headers)
except requests.ConnectionError as e:
	console.alert('Connection error', 'Could not login to \'%s\'. Check Blog URL.\n\nIf using Ghost Pro, SSL is enforced (use https://yourname.ghost.io)' %workflow.get_variable('url'))
	workflow.stop()

auth = json.loads(response.content)

try:
	access_token = auth['access_token']
	if len(access_token) < 10:
		raise KeyError
except KeyError:
	console.alert('Login error', 'Could not login to \'%s\'. Check Blog URL, username and password! \n\nIf using Ghost Pro, SSL is enforced (use https://yourname.ghost.io as URL)' %workflow.get_variable('url'))
	workflow.stop()

workflow.set_variable('token', access_token)
If action 'Upload new post' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Upload new post
Get document content ?
Folded Text
  • Include
  • Replace with:
Document content to variable text ?
Variable Name
text
Value
Input
Set Variable ?
Variable Name
slug
Value
Script - Prepare ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import xmltodict
import re
import markdown2
import console
import urllib
				
action_in = workflow.get_input()
token = workflow.get_variable('token')

text = workflow.get_variable("text")

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}
           
response = requests.get(workflow.get_variable('url') + 'api/v0.1/tags/', headers=headers)

workflow.set_variable('tags_blog', response.content)
#print('tags', response.content)
#print(json.dumps(json.loads(response.content), indent=2))

# Prepare post and upload
splitted = text.split('\n', 1)
title = splitted[0]
if title.startswith('#'):
	title = title[1:]
title = title.strip()
body = splitted[1]

workflow.set_variable('title', title)
workflow.set_variable('body', body)    
           
response = requests.get(workflow.get_variable('url') + 'api/v0.1/slugs/post/' + urllib.quote(title.encode('UTF-8')), headers=headers)

slugs = json.loads(response.content)
#print(json.dumps(slugs, indent=2))

slugs = slugs['slugs']

slug = ''
for item in slugs:
	slug = slug + str(item['slug'])

workflow.set_variable('slug', slug)

workflow.set_output(response.content)
UI - Post settings ?
User Interface
Presentation Style
  • Sheet
  • Full-Screen
  • Popover
Output
%ui:switch_status
Use Editor Theme
ON
Script - Upload post ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import xmltodict
import re
import markdown2
import console
				
action_in = workflow.get_input()
token = workflow.get_variable('token')

text = workflow.get_variable("text")

publishPost = workflow.get_variable("publishPost")
publishaspage = workflow.get_variable('publishaspage')
slug = workflow.get_variable('slug')
tags = workflow.get_variable('tags')

# Prepare post and upload
title = workflow.get_variable('title')
body = workflow.get_variable('body')

if publishPost ==  'ON':
	status = 'published'
else :
	status = 'draft'
	
if publishaspage == 'ON':
	page = 'true'
else:
	page = '0'

# create json for tags. We should use ids from existing tags, but that's annoying and Ghost handles it for us, so ...
tags_post = []
if tags != None:
	taglist = tags.split(',')
if tags != None and len(tags) > 0:
	tagkeys = ('id', 'name')
	for tagname in taglist:
		tagname = tagname.strip()
		if len(tagname) > 0:
			tag = dict.fromkeys(tagkeys)
			tag['id'] = 'null'
			tag['name'] = tagname
			tags_post.append(tag)
	
#print('tags_post', json.dumps(tags_post))	
newPost = '{"posts": [{"status" : "%s", "title": %s, "markdown": %s, "page": %s , "slug": "%s", "tags": %s}]}' % (status, json.dumps(title), json.dumps(body), page, slug.encode('UTF-8'), json.dumps(tags_post))

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}
           
response = requests.post(workflow.get_variable('url') + 'api/v0.1/posts/', data=newPost, headers=headers)

if response.status_code == 201:
	console.hud_alert('Post successfully uploaded', icon='success')
else:
	console.hud_alert('Error, Post not uploaded', icon='error')
	print(response.content)

workflow.set_output(response.content)
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'Upload image and insert url' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Upload image and insert url
Script - Upload image ?
Source Code
#coding: utf-8
import workflow
import photos
import requests
import re
import base64
import json
import console
import PIL
import editor

action_in = workflow.get_input()
token = workflow.get_variable('token')

# Attention: Content-Type must be set by library, not manually. Otherwise boundary won't be set correct
headers = {'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}
           
# Let user select photo from library          
selectedPhoto = photos.pick_image(original=True,
                                  raw_data=True,
                                  show_albums=True,
                                  include_metadata=True)

if not(selectedPhoto):
	workflow.stop()

# metadata
photoraw = selectedPhoto[0]
metadata = selectedPhoto[1]

filename = metadata.get('filename')
if not(filename) or filename == '':
	filename = 'postimage.jpg'
	
if filename.endswith('JPG') or filename.endswith('jpg') or filename.endswith('jpeg') or filename.endswith('JPEG'):
	mimetype = 'image/jpeg'
elif filename.endswith('PNG') or filename.endswith('png'):
	mimetype = 'image/png'
else:
	mimetype = 'image/jpeg'

# Give image here as binary string, will be encoded by requests library
files = {'uploadimage': (filename, b'%s' %photoraw, mimetype)} 

console.show_activity()
response = requests.post(workflow.get_variable('url') + 'api/v0.1/uploads', headers=headers, files=files)
console.hide_activity()

action_out = response.content[1:-1]
workflow.set_variable('imageurl', response.content[1:-1])

if response.status_code == 200:
	console.hud_alert('Image successfully uploaded', icon='success')
else:
	console.hud_alert('Error, image not uploaded', icon='error')
	workflow.stop()
	
# Check, if we should insert markdown for image or only url
output_image_markdown = True
selection = editor.get_selection()
text = editor.get_text()
# are we already within an image tag?
# get the surrounding of cursor and look for parentheses
n_start = max(0, selection[0] - 10)
n_end = min(len(text), selection[1] + 10)
n_before = selection[0] -n_start
n_after = n_end - selection[1]

searcharea = text[n_start:n_end]
searcharea_before = searcharea[0:n_before]
searcharea_after = searcharea[-n_after:]

if re.search('.*\]\( *', searcharea_before) and re.search(' *\).*', searcharea_after):
	output_image_markdown = False
else: 
	output_image_markdown = True 

if output_image_markdown:
	action_out = '![](' + action_out + ')'


workflow.set_output(action_out)
Set image url ar cursor position ?
Replacement Text
Input
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'Update post' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Update post
Get document content ?
Folded Text
  • Include
  • Replace with:
Document content to variable text ?
Variable Name
text
Value
Input
Set Variable ?
Variable Name
slug
Value
Set Variable ?
Variable Name
publishPost
Value
Set Variable ?
Variable Name
publishaspage
Value
Set Variable ?
Variable Name
tags
Value
Script - Get Posts ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
				
action_in = workflow.get_input()

text = workflow.get_variable("text")
token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

# Get posts to show user for update. Only get the most recent ones  
# Tradeoff between network traffic and the ability to really update any post
response = requests.get(workflow.get_variable('url') + 'api/v0.1/posts?limit=40&status=all&staticPages=all', headers=headers)
#print('Posts', response.headers, response.content)

postsJson = json.loads(response.content)
#print(json.dumps(postsJson, indent=2))

posts = postsJson['posts']
workflow.set_variable('posts', json.dumps(posts))
out_list = ''
for item in posts:
	out_list = out_list + str(item['id']) + ': ' + item['title'] + '\n'

action_out = out_list

workflow.set_output(action_out)
Select from List ?
Title
Select Post to be updated
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Script - Prepare ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import xmltodict
import re
import markdown2
import console
import urllib
				
action_in = workflow.get_input()

splitted = action_in.split(':', 1)
id = splitted[0]
title = splitted[1].strip()
workflow.set_variable('post_id_update', id)

posts = json.loads(workflow.get_variable('posts'))
for item in posts:
	if item['id'] == int(id):
		updated_post = item
		break

workflow.set_variable('slug', updated_post['slug'])

if updated_post['status'] == 'published':
	workflow.set_variable('publishPost', 'ON')
else:
	workflow.set_variable('publishPost', 'OFF')

if updated_post['page']	== 0:
	workflow.set_variable('publishaspage', 'OFF')
else: 
	workflow.set_variable('publishaspage', 'ON')

token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}
response = requests.get(workflow.get_variable('url') + 'api/v0.1/tags/', headers=headers)

workflow.set_variable('tags_blog', response.content)
#print('tags', response.content)
#print(json.dumps(json.loads(response.content), indent=2))
tags_blog = json.loads(response.content)['tags']
tags_dict = {}
#print('len(tags_blog)', len(tags_blog))
#print(json.dumps(tags_blog, indent=2))
for item in tags_blog:
	tags_dict.update({item['id']: item['name']})
	
i = 1
tagstring = ''
taglist = updated_post['tags']
#print('updated_post', updated_post)
for tagid in taglist:
	if i > 1 and tagid in tags_dict:
		tagstring = tagstring + ', ' 
	if tagid in tags_dict:
		tagstring = tagstring + tags_dict[tagid]
		i = i + 1

workflow.set_variable('tags', tagstring)

token = workflow.get_variable('token')

text = workflow.get_variable("text")

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}


# Prepare post and upload
splitted = text.split('\n', 1)
title = splitted[0]
if title.startswith('#'):
	title = title[1:]
title = title.strip()
body = splitted[1]

workflow.set_variable('title', title)
workflow.set_variable('body', body)    
           

workflow.set_output('0')
UI - Post settings ?
User Interface
Presentation Style
  • Sheet
  • Full-Screen
  • Popover
Output
%ui:switch_status
Use Editor Theme
ON
Script - Update Post ?
Source Code
#coding: utf-8
import workflow
import console
import json
import xmltodict
import re
import requests

action_in = workflow.get_input()

text = workflow.get_variable("text")
publishPost = workflow.get_variable("publishPost")
publishaspage = workflow.get_variable('publishaspage')
tags = workflow.get_variable('tags')

# Prepare post and upload it
splitted = text.split('\n', 1)
new_title = splitted[0]
if new_title.startswith('#'):
	new_title = new_title[1:]
	new_title.strip()
new_body = splitted[1]

if publishPost ==  'ON':
	new_status = 'published'
else :
	new_status = 'draft'
	
if publishaspage == 'ON':
	page = True
else:
	page = '0'

# create json for tags. We should use ids from existing tags, but that's annoying and Ghost handles it for us, so ...
tags_post = []
if tags != None:
	taglist = tags.split(',')
tagkeys = ('id', 'name')
if tags != None and len(tags) > 0:
	for tagname in taglist:
		tagname = tagname.strip()
		if len(tagname) > 0:
			tag = dict.fromkeys(tagkeys)
			tag['id'] = 'null'
			tag['name'] = tagname
			tags_post.append(tag)
	
post_id_update = workflow.get_variable('post_id_update')
posts = json.loads(workflow.get_variable('posts'))
for item in posts:
	if item['id'] == int(post_id_update):
		updated_post = item
		break


updated_post['slug'] = workflow.get_variable('slug').encode('UTF-8')
updated_post['title'] = new_title
updated_post['markdown'] = new_body
updated_post['status'] = new_status
updated_post['page'] = page
updated_post['tags'] = tags_post

token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

updated_post = '{"posts":[%s]}' %json.dumps(updated_post)

#print('updated_post', updated_post)

response = requests.put(workflow.get_variable('url') + 'api/v0.1/posts/' + post_id_update , data=updated_post, headers=headers)

if response.status_code == 200:
	console.hud_alert('Post successfully updated', icon='success')
else:
	console.hud_alert('Error, Post not updated', icon='error')
	print(response.content)

action_out = action_in
workflow.set_output(action_out)
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'Delete post' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Delete post
Script - Get Posts ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import xmltodict
import re
import markdown2
				
action_in = workflow.get_input()

text = workflow.get_variable("text")
token = workflow.get_variable('token')
headers = {'Content-Type': 'application/json',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

# Posts ermitteln
response = requests.get(workflow.get_variable('url') + 'api/v0.1/posts?limit=100&status=all&staticPages=all', headers=headers)

postsJson = json.loads(response.content)

posts = postsJson['posts']
workflow.set_variable('posts', json.dumps(posts))
out_list = ''
for item in posts:
	out_list = out_list + str(item['id']) + ': ' + item['title'] + '\n'


action_out = out_list
workflow.set_output(action_out)
Select from List ?
Title
Select post to be deleted
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Show Alert ?
Title
Really delete post
Message
Input
Button 1
OK
Output Value
Input
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Script - Delete Post ?
Source Code
#coding: utf-8
import workflow
import console
import json
import xmltodict
import re
import requests

action_in = workflow.get_input()
token = workflow.get_variable('token')
headers = {'Content-Type': 'application/json',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

#print('selected post', action_in)

splitted = action_in.split(':', 1)
id = splitted[0]
title = splitted[1].strip()

response3 = requests.delete(workflow.get_variable('url') + 'api/v0.1/posts/' + id ,  headers=headers)

if response3.status_code == 200:
	console.hud_alert('Post successfully deleted', icon='success')
else:
	console.hud_alert('Error, Post not deleted', icon='error')

#print('PUT-Response', response3.content)
action_out = action_in

workflow.set_output(action_out)
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'Fetch single post' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Fetch single post
Script - Get Posts ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import xmltodict
import re
import markdown2
				
action_in = workflow.get_input()

text = workflow.get_variable("text")
token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json; charset=UTF-8',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}
# Get posts for user selection
response = requests.get(workflow.get_variable('url') + 'api/v0.1/posts?limit=40&status=all&staticPages=all', headers=headers)

postsJson = json.loads(response.content)

posts = postsJson['posts']
workflow.set_variable('posts', json.dumps(posts))
out_list = ''
for item in posts:
	out_list = out_list + str(item['id']) + ': ' + item['title'] + '\n'

action_out = out_list
workflow.set_output(action_out)
Select from List ?
Title
Select post to be fetched
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Script - Set Text ?
Source Code
#coding: utf-8
import workflow
import console
import json
import xmltodict
import re
import requests
import editor

action_in = workflow.get_input()

splitted = action_in.split(':', 1)
id = splitted[0]
title = splitted[1].strip()

posts = json.loads(workflow.get_variable('posts'))
for item in posts:
	if item['id'] == int(id):
		updated_post = item
		break

text = workflow.get_variable("text")

new_title = updated_post['title']
if new_title.startswith('#'):
	new_title = new_title[1:]
title.strip()
new_body = updated_post['markdown']

updated_text = '# ' + new_title + '\n' + new_body

editor.replace_text(editor.get_selection()[0], editor.get_selection()[1], updated_text)

action_out = action_in
workflow.set_output(action_out)
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'Fetch all posts' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Fetch all posts
Script - Get Posts ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import xmltodict
import re
import markdown2
import editor
				
action_in = workflow.get_input()

token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

# Get all posts, including pages
response = requests.get(workflow.get_variable('url') + 'api/v0.1/posts?limit=100000&status=all&page=0&staticPages=all', headers=headers)

postsJson = json.loads(response.content)

posts = postsJson['posts']
workflow.set_variable('posts', json.dumps(posts))
out_list = ''
for item in posts:
	out_list = out_list + '# ' + item['title'] + '\n' + item['markdown'] + '\n\n\n'

# Insert posts at the beginning of the document
editor.replace_text(editor.get_selection()[0], editor.get_selection()[1], out_list)

workflow.set_output('0')
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'List posts' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
List posts
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import editor
				
action_in = workflow.get_input()
text = workflow.get_variable("text")
token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

# Get posts
response = requests.get(workflow.get_variable('url') + 'api/v0.1/posts?limit=100000&status=all&page=0&staticPages=all', headers=headers)

postsJson = json.loads(response.content)

posts = postsJson['posts']
workflow.set_variable('posts', json.dumps(posts))
out_list = ''
for item in posts:
	out_list = out_list + str(item['id']) + ';' + item['title'] + ';' + item['status'] + ';' + str(item['page']) + ';' + item['updated_at'] + '\n'

# Insert list of posts at beginning of document

editor.replace_text(editor.get_selection() [0], editor.get_selection()[1], 'Id;Title;Status;Is page;Updated at\n')
editor.replace_text(editor.get_selection() [0], editor.get_selection()[1], out_list)

workflow.set_output('0')
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
If action 'Get settings' ?
Run the block if
action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Get settings
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import requests
import console
import json
import editor
				
action_in = workflow.get_input()
text = workflow.get_variable("text")
token = workflow.get_variable('token')

headers = {'Content-Type': 'application/json',
           'X-Requested-With' : 'XMLHttpRequest',
           'Authorization' : 'Bearer %s' %token}

# Get settings
response = requests.get(workflow.get_variable('url') + 'api/v0.1/settings/', headers=headers)

# Insert settings as formatted JSON at beginning of document
editor.replace_text(  editor.get_selection()[0], editor.get_selection()[1], json.dumps(json.loads(response.content), indent=2))

workflow.set_output('0')
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped