Skip to content

Instantly share code, notes, and snippets.

@halspg halspg/day one webclip readme.md Secret
Last active Aug 29, 2015

Embed
What would you like to do?
Day One Webclip for Pythonista

Readme

Day One Webclip.py

ウェブページをMarkdown形式に変換してDay Oneへ保存します。送信にはDrafts 4を使用。

Drafts 4アクション

以下の2つをインストール。ドラフトにURLを貼り付けてDay One Webclipアクションを実行。

URLをコピーして直接Pythonistaでスクリプトを実行しても動作します。

Day One Webclip

x-drafts4://x-callback-url/import_action?v=2&tintColor=%5B%0A%20%200.224%2C%0A%20%200.792%2C%0A%20%200.827%0A%5D&shouldConfirm=0&logLevel=1&uuid=A1FB5CEC-3E72-42B8-8850-6A6DBADD85D0&disposition=3&actionSteps=%5B%0A%20%20%7B%0A%20%20%20%20%22urlTemplate%22%20%3A%20%22pythonista%3A%5C%2F%5C%2FDay%2520One%2520Webclip.py%3Faction%3Drun%26argv%3D%5B%5Bselection%5D%5D%22%2C%0A%20%20%20%20%22actionStepType%22%20%3A%20%22URL%22%0A%20%20%7D%0A%5D&description=&modifiedAt=2014-10-29%2012%3A12%3A18%20%2B0000&name=Day%20One%20Webclip&iconImageName=action_dropbox

Day One Webclip 2

x-drafts4://x-callback-url/import_action?v=2&tintColor=%5B%0A%20%200.224%2C%0A%20%200.792%2C%0A%20%200.827%0A%5D&shouldConfirm=0&logLevel=1&uuid=F44ECEBD-733A-4CC2-96B3-ACA28E09C718&disposition=3&actionSteps=%5B%0A%20%20%7B%0A%20%20%20%20%22writeType%22%20%3A%20%22create%22%2C%0A%20%20%20%20%22fileTemplate%22%20%3A%20%22%5B%5Bline%7C2..%5D%5D%22%2C%0A%20%20%20%20%22actionStepType%22%20%3A%20%22Dropbox%22%2C%0A%20%20%20%20%22folderTemplate%22%20%3A%20%22%5C%2F%E3%82%A2%E3%83%97%E3%83%AA%5C%2FDay%20One%5C%2FJournal.dayone%5C%2Fentries%5C%2F%22%2C%0A%20%20%20%20%22fileExtTemplate%22%20%3A%20%22doentry%22%2C%0A%20%20%20%20%22fileNameTemplate%22%20%3A%20%22%5B%5Btitle%5D%5D%22%0A%20%20%7D%0A%5D&description=&modifiedAt=2014-10-29%2012%3A10%3A18%20%2B0000&name=Day%20One%20Webclip%202&iconImageName=action_dropbox
# -*- coding: utf-8 -*-
import sys
import clipboard
import requests
import urllib2
import uuid
from datetime import datetime
from xml.sax.saxutils import *
import webbrowser
url=''
if len(sys.argv) != 1:
url = sys.argv[1].replace('\n', '')
else:
url = clipboard.get().replace('\n', '')
req = 'http://heckyesmarkdown.com/go/?read=1&preview=0&showframe=0&output=url&u=' + urllib2.quote(url.encode('utf-8'))
r = requests.get(req)
source = urllib2.unquote(r.text).encode('raw_unicode_escape').decode('utf-8')
source = escape(source)
utc = datetime.utcnow()
# y+"-"+m+"-"+d+"T"+hr+":"+min+":"+sec+"Z"
utc = utc.strftime('%Y-%m-%d'+'T'+'%H:%M:%S'+'Z')
uuid = str(uuid.uuid4()).split('-')
uuid = ''.join(uuid)
out = uuid+'\n<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n <key>Creation Date</key>\n <date>'+utc+'</date>\n <key>Creator</key>\n <dict>\n <key>Device Agent</key>\n <string>iPhone/iPhone6,1</string>\n <key>Generation Date</key>\n <date>'+utc+'</date>\n <key>Host Name</key>\n <string>iPhone 5s</string>\n <key>OS Agent</key>\n <string>iOS/8.1</string>\n <key>Software Agent</key>\n <string>Day One iOS/1.15.1</string>\n </dict>\n <key>Entry Text</key>\n <string>'+source+'</string>\n <key>Starred</key>\n <false/>\n <key>Tags</key>\n <array>\n <string>Webclip</string>\n </array>\n <key>Time Zone</key>\n <string>Asia/Tokyo</string>\n <key>UUID</key>\n <string>'+uuid+'</string>\n</dict>\n</plist>'
drafts = 'x-drafts4://x-callback-url/create?action='+urllib2.quote('Day One Webclip 2'.encode('utf-8'))+'&text='+urllib2.quote(out.encode('utf-8'))+'&afterSuccess=Delete'
webbrowser.open(drafts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.