<commit_before># Copyright (c) Metakernel Development Team.
# Distributed under the terms of the Modified BSD License.

from metakernel import Magic, option
from IPython.display import HTML
import urllib
try:
    import urlparse
except ImportError:
    from urllib import parse as urlparse
import os

try:
    urllib.URLopener
    def download(url, filename):
        opener = urllib.URLopener()
        opener.retrieve(url, filename)
except: # python3
    import urllib.request
    def download(url, filename):
        g = urllib.request.urlopen(url)
        with open(filename, 'wb') as f:
            f.write(g.read())        

class JigsawMagic(Magic):

    def line_jigsaw(self, language):
        """
        %jigsaw LANGUAGE - show visual code editor/generator

        This line magic will allow visual code editing or generation.

        Example:
            %jigsaw Processing
        """
        # Copy iframe html to here (must come from same domain):
        if not os.path.isfile("Processing.html"):
            download("https://calysto.github.io/jigsaw/" + language + ".html", 
                     language + ".html")
        # Display iframe:
        iframe = """<iframe src="%s.html" width="100%%" height="350" style="resize: both; overflow: auto;"></frame>""" % language
        self.kernel.Display(HTML(iframe))

def register_magics(kernel):
    kernel.register_magics(JigsawMagic)
<commit_msg>Jigsaw magic: download each time (until stable) and add IPython magic for it<commit_after># Copyright (c) Metakernel Development Team.
# Distributed under the terms of the Modified BSD License.

from metakernel import Magic, option
from IPython.display import HTML
import urllib
try:
    import urlparse
except ImportError:
    from urllib import parse as urlparse
import os

try:
    urllib.URLopener
    def download(url, filename):
        opener = urllib.URLopener()
        opener.retrieve(url, filename)
except: # python3
    import urllib.request
    def download(url, filename):
        g = urllib.request.urlopen(url)
        with open(filename, 'wb') as f:
            f.write(g.read())        

class JigsawMagic(Magic):

    def line_jigsaw(self, language):
        """
        %jigsaw LANGUAGE - show visual code editor/generator

        This line magic will allow visual code editing or generation.

        Example:
            %jigsaw Processing
        """
        # Copy iframe html to here (must come from same domain):
        ##if not os.path.isfile("Processing.html"):
        download("https://calysto.github.io/jigsaw/" + language + ".html", 
                 language + ".html")
        # Display iframe:
        iframe = """<iframe src="%s.html" width="100%%" height="350" style="resize: both; overflow: auto;"></frame>""" % language
        self.kernel.Display(HTML(iframe))

def register_magics(kernel):
    kernel.register_magics(JigsawMagic)

def register_ipython_magics():
    from metakernel import IPythonKernel
    from IPython.core.magic import register_line_magic
    kernel = IPythonKernel()
    magic = JigsawMagic(kernel)

    @register_line_magic
    def jigsaw(line):
        magic.line_jigsaw(line)
{'fraction_non_alphanumeric': 0.10231232182451695, 'fraction_numerical': 0.004434589800443459, 'mean_word_length': 2.8278787878787877, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908062', 'n_tokens_mistral': 966, 'n_tokens_neox': 921, 'n_words': 272}