Editorial Workflows

Day One Entry

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: This workflow has no description.

Shared by: @hals_pg

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# -*- coding: utf-8 -*-
import sys
import dropbox
import os
import workflow
import dialogs
import keychain
import editor
import uuid
from datetime import datetime
from xml.sax.saxutils import escape
import console


sys.setdefaultencoding('utf-8')

try:
	app_key, app_secret, access_type = keychain.get_password(
		'dropbox_utility',
		'dropbox_keys'
	).split('|')
except:
	dialogs.hud_alert(
		'Dropboxアプリを認証してください',
		'error', 1.5
	)
	workflow.stop()

token = keychain.get_password(
	'dropbox_utility',
	'dropbox_token'
)

session = dropbox.session.DropboxSession(
	app_key, app_secret, access_type
)

if token is not None:
	token_key, token_secret = token.split('|')
	session.set_token(
		token_key, token_secret
	)
else:
	dialogs.hud_alert(
		'認証エラー',
		'error', 1.5
	)
	workflow.stop()

client = dropbox.client.DropboxClient(session)

filepath = editor.get_path()
filename = os.path.basename(filepath)
filefolder = editor.get_selected_folder()
title, ext = os.path.splitext(filename)
body = editor.get_file_contents(
	os.path.join(
		filefolder[1], filename
	),
	filefolder[0]
)
source = '# {}\n\n{}'.format(title, body)
utc = datetime.utcnow()
utc = utc.strftime('%Y-%m-%d'+'T'+'%H:%M:%S'+'Z')

uuid = str(uuid.uuid4()).split('-')
uuid = ''.join(uuid).upper()

out = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Creation Date</key>
    <date>{1}</date>
    <key>Creator</key>
    <dict>
        <key>Device Agent</key>
        <string>iPhone/iPhone6,1</string>
        <key>Generation Date</key>
        <date>{1}</date>
        <key>Host Name</key>
        <string>iPhone 5s</string>
        <key>OS Agent</key>
        <string>iOS/8.4</string>
        <key>Software Agent</key>
        <string>Day One iOS/1.17.1</string>
    </dict>
    <key>Entry Text</key>
    <string>{2}</string>
    <key>Starred</key>
    <false/>
    <key>Tags</key>
    <array>
        <string>Webclip</string>
    </array>
    <key>Time Zone</key>
    <string>Asia/Tokyo</string>
    <key>UUID</key>
    <string>{0}</string>
</dict>
</plist>
'''[1:-1].format(
	uuid, utc, escape(source)
)
path = '/アプリ/Day One/Journal.dayone/entries/'
console.show_activity()
client.put_file(
	path + uuid + '.doentry', out
)
console.hide_activity()
console.hud_alert(
	'Saved', 'success', 0.5
)