Editorial Workflows

Gaddgict Update Post Template

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: Redacted version of the Update Post workflow used to update an existing post on my site over SFTP.

Shared by: Gaddgict.com / @SyrinxStarman

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Document Text ?
Folded Text
  • Include
  • Replace with:
Find ?
Search for
<!--fn (.*) fn-->
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Set Variable ?
Variable Name
fn
Value
Input
Check for Updated Tags/FIlename ?
Title
Redo tags and update filename?
Message
Button 1
Yes
Output Value
1
Button 2
No
Output Value
0
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Set Variable ?
Variable Name
boolUpdateTags
Value
Input
If… ?
Run the block if
boolUpdateTags
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
1
Document Text ?
Folded Text
  • Include
  • Replace with:
Find ?
Search for
<!--tag (.*) tag-->
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Change Case ?
  • UPPER CASE
  • lower case
  • Title Case
Find / Replace ?
Find
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
-
Set Variable ?
Variable Name
newTags
Value
Input
Generate Text ?
Text
fn
Find / Replace ?
Find
_(.*)_
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
_newTags_
Set Variable ?
Variable Name
newFileName
Value
Input
…End If
Get Current File Name ?
Include Folder
OFF
Include Extension
ON
Set Variable ?
Variable Name
edFileName
Value
Input
Document Text ?
Folded Text
  • Include
  • Replace with:
Find ?
Search for
<!--pt (.*) pt-->
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Set Variable ?
Variable Name
postType
Value
Input
Document Text ?
Folded Text
  • Include
  • Replace with:
Find ?
Search for
<!--pc (.*) pc-->
Match Group (RegEx)
1
Search Type
  • Regular Expression
  • Case-insensitive Search (A = a)
  • Case-sensitive Search (A ≠ a)
Output
  • Found Text
  • Range of Text (from:to)
Set Variable ?
Variable Name
postCategory
Value
Input
Document Text ?
Folded Text
  • Include
  • Replace with:
Set Variable ?
Variable Name
postContent
Value
Input
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import editor
import datetime
import paramiko
import console

#Get workflow variables
postType = workflow.get_variable('postType')
postCategory = workflow.get_variable('postCategory')
postContents = workflow.get_variable('postContent')
fileName = workflow.get_variable('fn')
edFileName = workflow.get_variable('edFileName')
boolUpdateTags = workflow.get_variable('boolUpdateTags')
newFileName = workflow.get_variable('newFileName')

#Set remote path on the server, along with username, host, and port
remotePath = "/blog/path/" + postCategory + "/" + postType + "/" + fileName
user = "user"
host = "example.com"
port = 1234

#Set path to local Editorial folder for private SSH key
editor_path = editor.get_path()
delim = "/"
ed_path_trunced = delim.join(editor_path.split('/', 7)[:7]) + "/Documents/Private/"

#Set log file for SSH module paramiko
paramiko.util.log_to_file(ed_path_trunced + 'paramiko.log')

#Specify SSH private key and connect to server
k = paramiko.RSAKey.from_private_key_file(ed_path_trunced + 'keyfile_name')
transport = paramiko.Transport((host, port))
transport.connect(username = user, pkey = k)
sftp = paramiko.SFTPClient.from_transport(transport)

#Get local file within Editorial
edFile = editor.get_path()

#If tags have been updated, reformulate the already-existing filename (HTMLy's format)
if boolUpdateTags == "1":
	sftp.remove(remotePath)
	remotePath = "/blog/path/" + postCategory + "/" + postType + "/" + newFileName
	fileName = newFileName

#Upload the file
sftp.put(edFile, remotePath)
console.hud_alert('Updated '+fileName, 'success')

sftp.close()
transport.close()

action_in = workflow.get_input()

# Extension point to do something after the file is uploaded
action_out = action_in

workflow.set_output(action_out)
Sub-Workflow ?
Workflow
Can Stop Main Workflow
OFF
If… ?
Run the block if
boolUpdateTags
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
1
Extend Selection ?
Direction
  • Backward
  • Forward
  • Both
Unit
  • Start/End of Document
  • Start/End of Line
  • Number of Characters...
1
Find / Replace ?
Find
<!--fn (.*) fn-->
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
<!--fn newFileName fn-->
Replace Selected Text ?
Replacement Text
Input
…End If
Open URL ?
Open in
  • In-App Browser
  • Default App / Safari
URL
https://gaddgict.com
Tab
  • Last-used Tab
  • New Tab
  • Tab with ID:
Unique identifier
Wait until Loaded
OFF
Reveal Browser Automatically
ON