Editorial Workflows

Insert Keywords

unlisted 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: Workflow to add keywords suggested by the Zemanta API into the YAML block of the currently editing document. Requires API key to be set in the workflow.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Zemanta API Key ?
Variable Name
API Key
Value
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
API Key Required!
…End If
Document Text ?
Folded Text
  • Include
  • Replace with:
Find YAML Range ?
Search for
^\s*---\n(.*\n)*?---\s*$
Match Group (RegEx)
0 (entire match)
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Select YAML Range ?
Range (from:to)
Input
Relative to
  • Entire Document
  • Current Selection
Document Text ?
Folded Text
  • Include
  • Replace with:
Get Keywords ?
Source Code
#coding: utf-8
import workflow
import urllib
import json
import yaml

#split the input into the YAML and the content
inputString = workflow.get_input()

contents = inputString.split('---',2)
yamlHeader = contents[1]

loadedYaml = yaml.load(yamlHeader)

#call the web service
gateway = 'http://api.zemanta.com/services/rest/0.0/'
args = {'method': 'zemanta.suggest',
        'api_key': workflow.get_variable('API Key'),
        'text': unicode(contents[2]).encode("utf-8"),
        'return_categories': 'dmoz',
        'format': 'json'}
args_enc = urllib.urlencode(args)
results_raw = urllib.urlopen(gateway, args_enc).read()
results = json.loads(results_raw)

#parse the results ans include items above some level of confidence
newKeywords = []

for item in results['keywords']:
	if item['confidence'] > 0.02:
		newKeywords.append(str(item['name']).lower().strip())
		
if len(newKeywords) > 0:
	loadedYaml['keywords'] = newKeywords
	
# set up the replacement YAML block
action_out = '---\n' + yaml.dump(loadedYaml) + '---\n'

workflow.set_output(action_out)
Replace YAML Header ?
Replacement Text
Input