-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d9c1d6a
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |