.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_gallery_plot_download_providers.py:
Download from Dropbox, Google Drive, and Github
-----------------------------------------------
It's also possible to download files from Github, Google Drive, and Dropbox.
While you can go through a little extra effort to get a direct download link,
``download`` will try to make things a little bit easier for you.
.. code-block:: default
from download import download
import matplotlib.pyplot as plt
import os.path as op
import shutil as sh
You can simply find the link to your content on GitHub and give it directly
to Download. It will try to be smart about converting the link where
necessary.
.. code-block:: default
url = "https://drive.google.com/file/d/0B8VZ4vaOYWZ3c3Y1c2ZQX01yREk/view?usp=sharing"
path = download(url, "./downloaded/citation.png", replace=True)
fig, ax = plt.subplots()
im = plt.imread(path)
ax.imshow(im)
ax.set_axis_off()
.. image:: /gallery/images/sphx_glr_plot_download_providers_001.png
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Downloading data from https://doc-0g-9c-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/5k38lin2cub2baoepd2f1h31d07bpljk/1587679275000/01085013503681928164/*/0B8VZ4vaOYWZ3c3Y1c2ZQX01yREk?e=download (35 kB)
file_sizes: 0%| | 0.00/35.6k [00:00, ?B/s]
file_sizes: 100%|##########################| 35.6k/35.6k [00:00<00:00, 4.29MB/s]
Successfully downloaded file to ./downloaded/citation.png
The same works for Google Drive content.
.. note:: Make sure your sharing options let any user access the file.
.. code-block:: default
url = "https://github.com/choldgraf/download/blob/master/examples/data/citation.png"
path2 = download(url, "./downloaded/citation2.png", replace=True)
fig, ax = plt.subplots()
im2 = plt.imread(path)
ax.imshow(im2)
ax.set_axis_off()
.. image:: /gallery/images/sphx_glr_plot_download_providers_002.png
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Downloading data from https://github.com/choldgraf/download/blob/master/examples/data/citation.png (1 byte)
file_sizes: 0%| | 0.00/1.00 [00:00, ?B/s]
file_sizes: 65.9kB [00:00, 5.02MB/s]
Successfully downloaded file to ./downloaded/citation2.png
Dropbox links also work, though in this case ``download`` will use
the ``requests`` library to download the file. This is because Dropbox
requires cookies and requests is smart about handling this.
.. code-block:: default
url = "https://www.dropbox.com/s/rlndt99tss65418/citation.png?dl=0"
path3 = download(url, "./downloaded/citation3.png", replace=True)
fig, ax = plt.subplots()
im3 = plt.imread(path3)
ax.imshow(im)
ax.set_axis_off()
sh.rmtree("./downloaded")
plt.show()
.. image:: /gallery/images/sphx_glr_plot_download_providers_003.png
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Successfully downloaded file to ./downloaded/citation3.png
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 2.055 seconds)
.. _sphx_glr_download_gallery_plot_download_providers.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_download_providers.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_download_providers.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_