Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding google drive rewrite provider #482

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nbviewer/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
for prov in ['url', 'github', 'gist']]

default_rewrites = ['nbviewer.providers.{}'.format(prov)
for prov in ['gist', 'github', 'dropbox', 'url']]
for prov in ['gist', 'github', 'dropbox', 'googledrive',
'url']]


def provider_handlers(providers=None):
Expand Down
1 change: 1 addition & 0 deletions nbviewer/providers/googledrive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .handlers import uri_rewrites
14 changes: 14 additions & 0 deletions nbviewer/providers/googledrive/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#-----------------------------------------------------------------------------
# Copyright (C) 2015 The Jupyter Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

def uri_rewrites(rewrites=[]):
return rewrites + [
(r'^http(s?)://drive\.google\.com/file/d/([^/]*).*$',
u'/url{0}/googledrive.com/host/{1}'),
(r'^http(s?)://drive\.google\.com/open\?id=([^&#]*).*$',
u'/url{0}/googledrive.com/host/{1}')
]
5 changes: 5 additions & 0 deletions nbviewer/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def test_transform_ipynb_uri():
u'/urls/dl.dropbox.com/s/zip/baz.qux'),
( u'https://www.dropbox.com/sh/mhviow274da2wly/CZKwRRcA0k/nested/furthernested/User%2520Interface.ipynb?dl=1',
u'/urls/dl.dropbox.com/sh/mhviow274da2wly/CZKwRRcA0k/nested/furthernested/User%2520Interface.ipynb'),
# Google Drive URLS
(u'http://drive.google.com/file/d/0B7d519FxJIqPYktaTVg1TTV1WDA/view?usp=sharing',
'/url/googledrive.com/host/0B7d519FxJIqPYktaTVg1TTV1WDA'),
(u'https://drive.google.com/open?id=0B7d519FxJIqPcEVOZXYzdGxBdzQ',
u'/urls/googledrive.com/host/0B7d519FxJIqPYktaTVg1TTV1WDA'),
# URL
('https://example.org/ipynb',
u'/urls/example.org/ipynb'),
Expand Down