├── jupyter_disqus ├── tests │ ├── __init__.py │ └── test_app.py ├── __init__.py └── app.py ├── MANIFEST.in ├── .coveragerc ├── demo.gif ├── readthedocs.yml ├── .travis.yml ├── setup.py ├── .gitignore ├── LICENSE └── README.rst /jupyter_disqus/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = jupyter_disqus/tests/* 3 | -------------------------------------------------------------------------------- /jupyter_disqus/__init__.py: -------------------------------------------------------------------------------- 1 | from .app import inject 2 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vwxyzjn/jupyter_disqus/HEAD/demo.gif -------------------------------------------------------------------------------- /readthedocs.yml: -------------------------------------------------------------------------------- 1 | python: 2 | version: 3 3 | pip_install: true 4 | 5 | # For more fields that can be specified here, see: 6 | # http://docs.readthedocs.io/en/latest/yaml-config.html 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This is a simple Travis config for a project that only needs to install pure 2 | # Python dependencies. For more complex setups, you can use conda on Travis: 3 | # http://conda.pydata.org/docs/travis.html 4 | 5 | language: python 6 | python: 7 | - "3.6" 8 | - "3.5" 9 | - "3.4" 10 | # Install any dependencies for running the tests: 11 | install: 12 | - pip install codecov pytest-cov 13 | - pip install -e . 14 | # command to run tests 15 | script: py.test --cov=jupyter_disqus --cov-config .coveragerc 16 | after_success: 17 | codecov 18 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | with open('README.rst') as f: 4 | readme = f.read() 5 | 6 | setup( 7 | name='jupyter_disqus', 8 | version='0.1.2', 9 | description='Add disqus to your jupyter notebook', 10 | long_description=readme, 11 | author='Costa Huang', 12 | author_email='costa.huang@outlook.com', 13 | install_requires=['IPython', 'htmlmin==0.1.12'], 14 | packages=['jupyter_disqus', 'jupyter_disqus.tests'], 15 | classifiers=[ 16 | 'License :: OSI Approved :: BSD License', 17 | 'Programming Language :: Python :: 3', 18 | ], 19 | url="https://github.com/vwxyzjn/jupyter_disqus" 20 | ) 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # Installer logs 29 | pip-log.txt 30 | pip-delete-this-directory.txt 31 | 32 | # Unit test / coverage reports 33 | htmlcov/ 34 | .tox/ 35 | .coverage 36 | .coverage.* 37 | .cache 38 | nosetests.xml 39 | coverage.xml 40 | *,cover 41 | .hypothesis/ 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Sphinx documentation 48 | docs/_build/ 49 | 50 | #Ipython Notebook 51 | .ipynb_checkpoints 52 | 53 | \.mypy_cache/ 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-Present Shengyi (Costa) Huang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /jupyter_disqus/tests/test_app.py: -------------------------------------------------------------------------------- 1 | from jupyter_disqus.app import _format_disqus_code 2 | from unittest.mock import MagicMock 3 | 4 | def test_format_disqus_code(): 5 | assert _format_disqus_code( 6 | page_url="https://costahuang.me/SC2AI/", 7 | page_identifier="1f527ae5-5a59-4dc3-9bb0-d77c2ccf5cab", 8 | site_shortname="costahuang" 9 | ) == "
" -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Jupyter_Disqus Package 2 | ======================= 3 | 4 | .. image:: https://travis-ci.org/vwxyzjn/jupyter_disqus.svg?branch=master 5 | :target: https://travis-ci.org/vwxyzjn/jupyter_disqus 6 | 7 | .. image:: https://codecov.io/gh/vwxyzjn/jupyter_disqus/branch/master/graph/badge.svg 8 | :target: https://codecov.io/gh/vwxyzjn/jupyter_disqus 9 | 10 | .. image:: https://badge.fury.io/py/jupyter-disqus.svg 11 | :target: https://badge.fury.io/py/jupyter-disqus 12 | 13 | Introduction 14 | --------------------------- 15 | 16 | You may use this package to inject and display `Disqus `_ in your jupyter notebook, which might be helpful for couple use cases. For example, if you are doing a tutorial or a demonstration, ``Jupyter_Disqus`` allows you to answer questions that other people may have. Also, you may get some helpful feedback from the audience as well. 17 | 18 | Demo 19 | ----------------------- 20 | 21 | .. image:: https://github.com/vwxyzjn/jupyter_disqus/raw/master/demo.gif 22 | :target: https://github.com/vwxyzjn/jupyter_disqus/raw/master/demo.gif 23 | 24 | 25 | Installation 26 | ------------------------- 27 | 28 | :: 29 | 30 | $ pip install jupyter_disqus 31 | 32 | 33 | Usage 34 | ---------------------- 35 | 36 | .. code-block:: python 37 | 38 | from jupyter_disqus import inject 39 | # make sure to run this in a cell of your jupyter notebook 40 | inject( 41 | page_url="https://costahuang.me/SC2AI/", 42 | page_identifier="1f527ae5-5a59-4dc3-9bb0-d77c2ccf5cab", # unique identifier 43 | site_shortname="costahuang" # your disqus site shortname 44 | ) 45 | 46 | Authors: Costa Huang 47 | -------------------------------------------------------------------------------- /jupyter_disqus/app.py: -------------------------------------------------------------------------------- 1 | from IPython.display import HTML 2 | import IPython 3 | import htmlmin 4 | 5 | def _format_disqus_code(page_url: str, page_identifier: str, site_shortname: str) -> str: 6 | """This function formats the necessary html and javascript codes needed to be 7 | inserted into the jupyter notebook 8 | 9 | Args: 10 | page_url (str): your page's canonical URL 11 | page_identifier (str): your page's unique identifier 12 | site_shortname (str): your site's disqus shortname 13 | 14 | Returns: 15 | str: the formatted html disqus code 16 | 17 | """ 18 | disqus_code = """ 19 |
20 | 37 | 38 | 39 | 40 | """ % (page_url, page_identifier, site_shortname, site_shortname) 41 | 42 | return htmlmin.minify(disqus_code) 43 | 44 | def inject(page_url: str, page_identifier: str, site_shortname: str) -> IPython.core.display.HTML: 45 | """this function injects and displays a disqus commenting section in a code cell of your jupyter notebook 46 | Args: 47 | page_url (str): your page's canonical URL 48 | page_identifier (str): your page's unique identifier 49 | site_shortname (str): your site's disqus shortname 50 | 51 | Returns: 52 | IPython.core.display.HTML 53 | 54 | Example: 55 | >>> from jupyter_disqus import inject 56 | >>> # call this function in a separate code cell of your jupyter notebook 57 | >>> inject( 58 | page_url="https://costahuang.me/SC2AI/", 59 | page_identifier="1f527ae5-5a59-4dc3-9bb0-d77c2ccf5cab", 60 | site_shortname="costahuang" 61 | ) 62 | """ 63 | return HTML(_format_disqus_code(page_url, page_identifier, site_shortname)) 64 | --------------------------------------------------------------------------------