Editorial Workflows

Post to mico.blog

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: Based on jbwhaley’s [Pythonista script](https://gist.github.com/jbwhaley/126ddcd807bf5ff95909a78d863e1e6d#file-microblogger-py) this workflow takes the selected text, posts it to micro.blog, and archives the post in its own Markdown file.

Shared by: @macdhuibh

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Selected Text ?
Entire Line(s)
ON
Empty Selection Output
  • No Output
  • All Text
  • Closest Word
Folded Text
  • Include
  • Replace with:
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import requests
import sys
import webbrowser


content = workflow.get_input()
print(content)

# Replace the 'API_KEY' value below with your API key;
# get one at https://micro.blog/account

API_KEY = "XXXXXXXXXXXXXXXXXX"
HEADER_VALUE = "Bearer " + API_KEY

# Grab input from Drafts

def send_request(content):
    # Request
    # POST https://micro.blog/micropub

    try:
        response = requests.post(
            url="https://micro.blog/micropub",
            headers={
                "Authorization": HEADER_VALUE,
                "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            },
            data={
                "h": "entry",
                "content": content,
            },
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
        
    except requests.exceptions.RequestException:
        print('HTTP Request failed')


send_request(content)

workflow.set_output(content)
Set Variable ?
Variable Name
new post
Value
Input
Set Variable ?
Variable Name
filename
Value
File Name-Year: 2001-Month: January-Day: 01-Hour: 01 (24h)-Minute: 01.md
Set File Contents ?
File Name
%var:filename
In Dropbox
ON
New Text
new post
If File Does Not Exist
  • Create
  • Stop Workflow