Skip to content

Commit

Permalink
1st commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentzca committed Oct 5, 2019
0 parents commit d9c1d6a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Alfred Dropbox Paper Workflow

List and open your Dropbox Paper documents.

## Requirement

- Alfred 3 or 4.
- Python 3.x
- Dropbox access Token
- https://www.dropbox.com/developers/apps/create

## Install

Download and double-click.

- https://github.com/lorentzca/alfred-dropboxpaper-workflow/releases/latest

## Usage

Register Dropbox access token. The access token saved in your "Keychain Access.app".

![](./images/image2.png)

List your Dropbox Paper documents.

![](./images/image1.png)
Binary file added images/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import urllib.request
import os
import json

endpoint = 'https://api.dropboxapi.com'
token = os.environ['DROPBOX_ACCESS_TOKEN']

def get_docs_list():
path = '/2/paper/docs/list'
url = endpoint + path
headers = {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
}
data = {
'limit': 1000
}

req = urllib.request.Request(
url, json.dumps(data).encode(), headers)
with urllib.request.urlopen(req) as response:
body = json.load(response)

return body

def get_title_list(docs_list):
path = '/2/paper/docs/download'
url = endpoint + path

title_list = []
for doc_id in docs_list['doc_ids']:
headers = {
'Authorization': 'Bearer ' + token,
'Dropbox-API-Arg': '{"doc_id":"%s","export_format":{".tag":"markdown"}}' % doc_id,
}

req = urllib.request.Request(url, headers = headers)
with urllib.request.urlopen(req) as response:
body = response.read().decode('utf-8')

title = {'title': body.splitlines()[0].lstrip('# '), 'doc_id': doc_id}
title_list.append(title)

return title_list

def alfred_items(title_list):
item_list = []
items = {'items': item_list}

for tl in title_list:
doc_url = 'https://paper.dropbox.com/doc/%s' % tl['doc_id']
item = {'title': tl['title'], 'arg': doc_url}
item_list.append(item)

return items

def main():
d = get_docs_list()
t = get_title_list(d)
a = alfred_items(t)

print(json.dumps(a))

main()

0 comments on commit d9c1d6a

Please sign in to comment.