Пример #1
0
def assert_same_html(asserter: TestCase, actual: str, expected: str):
    """
        Tests whether two HTML strings are 'equivalent'
    """
    bactual = HTMLBeautifier.beautify(actual)
    bexpected = HTMLBeautifier.beautify(expected)
    asserter.assertMultiLineEqual(bactual, bexpected)
Пример #2
0
    def write(self):
        css_template = "<style>\n{}\n</style>"
        html_inner = ET.tostring(self.main_el, method="html", encoding='unicode')
        styles = ''.join([css_template.format(css) for css in self.css_files])

        toc = ''
        if len(self.toc) > 0:
            toc = ET.tostring(self._table_of_contents(), method="html", encoding='unicode')
        # Get my HTML templae and render it

        with open(os.path.join(self.template_path, 'template.html')) as t:
            template = Template(t.read())

        now = datetime.datetime.now()
        final_render = HTMLBeautifier.beautify(template.render(report={
            'title': self.xml_project.XMLBuilder.find('Name').text,
            'ProjectType': self.xml_project.XMLBuilder.find('ProjectType').text,
            'MetaData': self.xml_project.get_metadata_dict(),
            'date': now.strftime('%B %d, %Y - %I:%M%p'),
            'Warehouse': self.xml_project.get_metadata_dict(tag='Warehouse'),
            'head': styles,
            'toc': toc,
            'body': html_inner,
            'footer': self.footer
        }))
        with open(self.filepath, "w", encoding="utf-8") as f:
            f.write(final_render)

        self.log.debug('Report Writing Completed')
Пример #3
0
 def write_html(self, meta, pages, cover):
     template = lookup.get_template('post.html')
     self.html = self.render_html()
     html = template.render(meta=meta, pages=pages, cover=cover, post=self)
     f = open(self.dest_folder() + '/index.html', 'w')
     f.write(HTMLBeautifier.beautify(html, 4))
     f.close()
Пример #4
0
def writeHtml(nString, txt):
    
    deleteFiles('./static/stylesheets/')
    deleteFiles('./static/javascript')

    txt = txt.replace('"//', '"https://')
    txt = txt.replace("'/", "'"+nString+'/')
    html = txt.replace('"/', '"'+nString+'/')

    soup = bs(html, 'html.parser')

    urlList = links('a', "rel", "", 'href', soup)
    jsList = links('script', "", "", 'src', soup)
    cssList = links('link', "rel", "stylesheet", 'href', soup)

    html = inputURL(html, urlList, nString)
    inputHtml = inputJS(jsList, "js", html)
    finalHtml = inputCSS(cssList, "css", inputHtml)

    try:
        finalHtml = HTMLBeautifier.beautify(finalHtml, 4)
    except:
        pass

    s = finalHtml.encode('utf-8', 'ignore')
    with open(link, 'wb') as f:
        f.write(s)
        f.close
Пример #5
0
def format_html(response):
    if response.mimetype == "text/html":
        if app.config.get('PRETTY_HTML', False):
            response.data = HTMLBeautifier.beautify(response.data, 2)
        elif app.config.get('MINIFY_HTML', False):
            response.data = minify(response.data)
    return response
Пример #6
0
def get_stats_table():
    global FILELINK

    try:
        start = (request.args['start'])
        end = (request.args['end'])

    except:
        request_str = get_default_request_string()
        return redirect(request_str)

    start_date_month, start_date_year = start.split('/')
    end_date_month, end_date_year = end.split('/')

    if (start_date_year > end_date_year) or \
            ((start_date_year == end_date_year) and (start_date_month > end_date_month)):
        request_str = get_default_request_string()
        return render_template('error.html', request_string=request_str), 400
    actual_date = dbr.get_actual_date_from_database()

    now = dt.datetime.now()
    years = list(range(2011, now.year + 1))
    dataDB, last_player_before_losers = dbr.get_stats(start, end)
    table_html = dataDB.to_html(classes='tablesorter" id="statistics')
    table_html = re.sub('dataframe ', '', table_html)

    if (re.match('[\d][\d]/[\d][\d][\d][\d]', start) is not None) \
            and (re.match('[\d][\d]/[\d][\d][\d][\d]', end) is not None):
        return HTMLBeautifier.beautify(render_template('table.html', table=table_html, years=years, start=start,
                                                       end=end, last_player_before_losers=last_player_before_losers,
                                                       actual_date=actual_date, source_file=FILELINK), 4)
Пример #7
0
 def assemble(self, page):
     """Assemble a web page"""
     html = self.include(page)
     html = HTMLBeautifier.beautify(html, 4)
     path = osp.join(self.dst, page)
     with open(path, "wt") as fp:
         fp.write(html)
Пример #8
0
        async def newfunc(*args, **kwargs):
            if config.cache:
                tem = template
            else:
                tem = airspeed.Template(readfile(filename), filename)

            objects = await func(*args, **kwargs)

            if type(objects) is response.HTTPResponse:
                return objects

            objects.update({
                "strip_unit": strip_unit,
                "escape_html": escape_html,
                "escape_url": escape_url,
                "get_colorscheme": colorscheme.get
            })

            if config.prettifyHTML:
                return response.html(
                    HTMLBeautifier.beautify(tem.merge(
                        objects, loader=VelocityFileLoader()),
                                            indent=4))  #.replace("/>", ">")
            else:
                return response.html(
                    tem.merge(objects, loader=VelocityFileLoader()))
Пример #9
0
 def format_html(self):
     self.VIEW.get_active_input().setReadOnly(False)
     self.VIEW.formatting_actions.setDisabled(True)
     self.VIEW.default_previev_action.setDisabled(False)
     self.VIEW.compression_action.setDisabled(False)
     html = self.VIEW.get_active_html_edit().toPlainText()
     html = HTMLBeautifier.beautify(html, 4)
     self.VIEW.set_html_editor(html)
Пример #10
0
def cleanHtml(src):
    with codecs.open(src, "r", "utf-8") as f:
        htmlFile = f.read()
        htmlClean = HTMLBeautifier.beautify(htmlFile, 4)
        print(htmlClean)

    with codecs.open(src, "w", "utf-8") as f:
        f.write(str(htmlClean))
Пример #11
0
 def change_html_preview(self):
     name = self.MODEL.get_file_title()
     init_tags = Constants.HTML_CONTENT
     content = self.VIEW.get_active_input().toPlainText()
     content = markdown.markdown(content)
     init_tags = init_tags.format(name, content)
     self.VIEW.set_preview(init_tags)
     if (self.VIEW.default_previev_action.isEnabled() == True):
         init_tags = HTMLBeautifier.beautify(init_tags, 4)
     self.VIEW.set_html_editor(init_tags)
def write(notebook, notes, out_dir=""):
    notebook_name = notebook.name
    count = 0
    totalCount = len(notes)
    for n in notes:
        count += 1
        title = n.title
        print "\t\t{count} of {total}:\t{note}".format(count=count, total=totalCount, note=title)
        title = validate_filename(title)
        dir = "{out_dir}{parent}/{child}".format(parent=notebook_name, child=title, out_dir=out_dir)
        note_updated = note_has_updated(n, dir)
        if note_updated is False:
            continue
        if not os.path.exists(dir):
            os.makedirs(dir)
        n = noteStore.getNote(token, n.guid, True, True, False, False)
        enml = n.content
        validate_filenames(n.resources)
        resources = n.resources
        tags = []
        if n.tagGuids:
            for i in n.tagGuids:
                tag = noteStore.getTag(i)
                tags.append(tag.name)

        # Print information about the note to file
        info = {"title": title, "created": n.created, "updated": n.updated, "enml?": enml != None, "tags": tags}
        outinfo = "{dir}/info.json".format(dir=dir)
        if resources:
            info["resources_count"] = len(resources)
        with open(outinfo, "w") as f:
            f.write(json.dumps(info, indent=2, sort_keys=True))

        if enml:
            html = process_enml_media(enml, resources)
            html_pretty = HTMLBeautifier.beautify(html, 2)
            with open("{dir}/content.html".format(dir=dir), "w") as f:
                f.write(html_pretty.encode("utf8"))
        if resources:
            dir = "{dir}/attachments".format(dir=dir)
            if not os.path.exists(dir):
                os.makedirs(dir)
            for r in resources:
                filename = r.attributes.fileName
                if not filename:
                    filename = "".join(
                        random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10)
                    )
                    filename = add_filename_type(filename, r.mime)
                with open("{dir}/{filename}".format(dir=dir, filename=filename), "wb") as f:
                    f.write(bytearray(r.data.body))
        info["success"] = True
        with open(outinfo, "w") as f:
            out = json.dumps(info, indent=2, sort_keys=True)
            f.write(out.encode("utf8"))
Пример #13
0
def generateXML(json, html):

    #Create an temporary html file
    file = open("tmp.html", "w")

    #Generates an unformatted html file from an json file
    os.system("python3 ./bin/htmlPython.py " + json + " > " + html)

    #Writes the unformatted html file into our temporary html file formatted
    file.write(HTMLBeautifier.beautify(open(html), 4))
    file.close()
Пример #14
0
def render_html(**context):
    dir_path = os.path.dirname(os.path.realpath(__file__))
    env = Environment(loader=FileSystemLoader(dir_path))
    env.filters["datetimeformat"] = datetimeformat
    env.filters["structformat"] = structformat

    template = env.get_template("template.htm")
    html = template.render(**context)

    pretty_html = HTMLBeautifier.beautify(html, 4)

    return pretty_html
def operation_on_file(*args):
    file_path = WORKING_PATH + args[0]
    if len(args) > 1:
        operation = 'w+'
    else:
        operation = 'r'

    with open(file_path, operation) as operation_place:
        if len(args) > 1:
            operation_place.write(args[1])
        else:
            return HTMLBeautifier.beautify(''.join(
                operation_place.readlines()))
Пример #16
0
def result():
    try:
        url = request.form['url']
        meth = request.form['method']
        print(meth)
        if (url[0:4] != 'http' or url[0:5] != "https"):
            url = "http://" + url
        attr = request.form.to_dict()
        attr.pop('url')
        attr.pop('method')
        headers = attr
        req = requests.get(url, headers=headers)

        if (meth == "Post"):
            req = requests.post(url, headers=headers)
        elif (meth == "Delete"):
            req = requests.delete(url, headers=headers)
        elif (meth == "Head"):
            req = requests.head(url, headers=headers)
        elif (meth == "Put"):
            req = requests.put(url, headers=headers)

        res_headers = req.headers

        client = pymongo.MongoClient("mongodb://localhost:27017/")
        dataBase = client['header_visualiser']
        COLLECTION_NAME = "req_res"
        collection = dataBase[COLLECTION_NAME]
        dt = datetime.now()
        record = {
            'date': dt,
            'request': req.request.headers,
            'response': res_headers
        }
        collection.insert_one(record)
        text = HTMLBeautifier.beautify(req.text, 4)

        content = {
            "res_headers": res_headers,
            "r_url": req.url,
            'req': req,
            'text': text
        }
        return render_template('result.html', **content)
    except Exception:
        return render_template('index.html', query="No such url exist!")
Пример #17
0
def renderSubtemplate(templateOutputPathForSubfile, template,
                      templateDataGenerator, templateParameters,
                      templateDataFilename, indexNo):
    """
        Generates one of the HTML templates listed by DataGenerator.
    """
    templateParametersForSubfile = templateParameters

    templateParametersPrepared = templateDataGenerator.prepareData(
        templateParameters, templateDataFilename, indexNo)
    if templateParametersPrepared is not None:
        templateParametersForSubfile = templateParametersPrepared

    with open(templateOutputPathForSubfile, 'wb') as out:
        out.write(
            HTMLBeautifier.beautify(
                template.render(**templateParametersForSubfile),
                4).encode('utf-8'))
Пример #18
0
def beautify(raw: str, content_type: str, extension: str=None):
    content_type = parse_content_type(content_type)

    try:
        if extension == 'js' or content_type == 'application/javascript':
            return JSBeautifier.beautify(raw)
        if extension == 'json' or content_type == 'application/json':
            try:
                return json.dumps(json.loads(raw), indent=2, sort_keys=True)
            except json.decoder.JSONDecodeError:
                return raw
        if extension == 'css' or content_type == 'text/css':
            return CSSBeautifier.beautify(raw)

        if content_type == 'text/html':
            return HTMLBeautifier.beautify(raw)
    except:
        return raw

    return raw
Пример #19
0
        async def newfunc(*args, **kwargs):
            if config.cache:
                tem = template
            else:
                tem = airspeed.Template(readfile(filename), filename)

            objects = await func(*args, **kwargs)

            if type(objects) is response.HTTPResponse:
                return objects

            objects.update({
                "strip_unit": strip_unit,
                "escape_html": escape_html,
                "escape_url": escape_url,
                "get_colorscheme": colorscheme.get
            })

            if config.prettifyHTML:
                res = response.html(
                    HTMLBeautifier.beautify(tem.merge(
                        objects, loader=VelocityFileLoader()),
                                            indent=4))  #.replace("/>", ">")
            else:
                res = response.html(
                    tem.merge(objects, loader=VelocityFileLoader()))

            if "write_cookies" in objects and isinstance(
                    objects["write_cookies"], dict):
                for cookie, value in objects["write_cookies"].items():
                    res.cookies[cookie] = value

            if "delete_cookies" in objects and isinstance(
                    objects["delete_cookies"], list):
                print(objects["delete_cookies"])
                for cookie in objects["delete_cookies"]:
                    del res.cookies[cookie]

            return res
Пример #20
0
def show(config):
    """show a confluence item


    """
    """show a confluence item

    If specifying data selector file, there is added a special field
    body['data'] to each page.

    Format of selector file:

    select: <CSS Selector for jQuery>
    list:
        - attr: href
          name: href

    Following keys:

    - list: each item produces a list item.  Input is current selected element.
    - object: each item produces a object property.  Each item must have "name"
        key for specifing the properties name
    - attr: read named attribute from current selected element
    - select: find elements using this selector.  For each of them apply current
      spec
    - text: 'text' or 'html'.  this is the default and default is to return
        'text'.

    Examples:

     - `ct show "SpaceName:Some Title"`

        gets page information which can be expanded

     - `ct show "SpaceName:Some Title" -e body`

        gets page information with expanded body (can also be expanded)

     - `ct show "SpaceName:Some Title" -e body,container`

        gets page information and expand more than one

     - `ct show "SpaceName:Some Title" -e 'body.view' -F '{body[view][value]}'`

        gets page information with more detailed expanded body (this is --html)

     - `ct show "SpaceName:Some Title" -F {_links[self]}`

        gets "self"-link expanded from "_links" from "Some Title"
    """
    first = True

    mustache, format, printf = None, None, None

    output_filter = lambda x: x

    if not config.get('format') and not config.get('expand'):
        if config.get('html'):
            config['format'] = u'{body[view][value]}'
            config['expand'] = 'body.view'

            from html5print import HTMLBeautifier
            output_filter = lambda x: HTMLBeautifier.beautify(x, 4)

        elif config.get('storage'):
            config['format'] = u'{body[storage][value]}'
            config['expand'] = 'body.storage'

            from html5print import HTMLBeautifier
            output_filter = lambda x: HTMLBeautifier.beautify(x, 4)

        elif config.get('ls'):
            config['format'] = u'{id}  {spacekey}  {title}'
            config['field'] = ['id', 'spacekey', 'title']

    results = []
    log.debug('config: %s', config.args)
    kwargs = config.dict('cql', 'expand', 'filter', 'state')
    log.debug('kwargs: %s', kwargs)
    kwargs['cql'] = config.confluence_api.resolveCQL(kwargs['cql'])

    for page in config.confluence_api.getPages(**kwargs):
        rec = page.dict(*config['field'])
        if config.get('beautify'):
            from html5print import HTMLBeautifier
            if rec.get('body', {}).get('storage', {}).get('value'):
                rec['body']['storage']['value'] = HTMLBeautifier.beautify(
                    rec['body']['storage']['value'], 4)
            if rec.get('body', {}).get('view', {}).get('value'):
                rec['body']['view']['value'] = HTMLBeautifier.beautify(
                    rec['body']['view']['value'], 4)

        results.append(rec)

    if config.get('format'):
        for result in results:
            if '{}' in config['format']:
                fields = [result[f] for f in config['field']]
                print config['format'].format(*fields)

            print output_filter(unicode(
                config['format']).format(**result)).encode('utf-8')

    elif config.get('data'):
        if config.get('data') == '-':
            data = get_list_data(sys.stdin.read())
        else:
            with open(config.get('data'), 'r') as f:
                data = get_list_data(f.read())

        from ..data_generator import generate_data

        pyaml.p(generate_data(data, results))

    else:
        if len(results) == 1:
            results = results[0]

        if config['write'] == 'json':
            import json
            json.dump(results, sys.stdout)

        elif config['write'] == 'yaml':
            import pyaml
            pyaml.p(results)
runpy3 () {
/usr/local/bin/python3 << 'EOF' - "$@"

import sys
from html5print import HTMLBeautifier
import clipboard
import pyautogui
#你的其他模块

for f in sys.argv:
	target = clipboard.paste()

	clipboard.copy(HTMLBeautifier.beautify(target, 4))

	pyautogui.keyDown('command')
	pyautogui.press('v')
	pyautogui.keyUp('command')
EOF
}

runpy3 "$@"
Пример #22
0
baseline = [(f,
             readoutput(TEST_PATH + "results/" + splitext(f)[0] + ".xidv.out"),
             process(f)) for f in listdir(BUNDLE_PATH)
            if isfile(join(BUNDLE_PATH, f))]

# sorting on first img, even if there are multiple images/bundle
sortimgs = sorted(baseline, key=lambda img: img[2][0][2])

data = [['h1', strftime("%Y-%m-%d %H:%M:%S", gmtime())],
        [[['hr'], ['h1', x[0]],
          [
              'table', ['tr', ['td', x[1].replace("\n", "<br />")]],
              ['tr', [['td', ['h2', "expected"]], ['td', ['h2', "actual"]]]],
              [[
                  'tr',
                  [['td', ['img', {
                      'src': i[0]
                  }]], ['td', ['img', {
                      'src': i[1]
                  }]]]
              ] for i in x[2]]
          ]] for x in sortimgs[::-1]]]

myhtml = html(data)

pretty = HTMLBeautifier.beautify(myhtml, 2)

f = open(TEST_PATH + 'compare.html', 'w')
f.write(pretty)
f.close()
Пример #23
0
    else:
        a0 = '<a href=' + d[
            'Paper'] + ' target="_blank" class="btn btn-primary">Paper</a>'
        loop += onecol(a0)

    loop += temp4

    loop += '</div>'

    if col == cols - 1:
        loop += '</div>'

    col = (col + 1) % cols

while col != 0:
    loop += '<div class="col">'
    loop += '</div>'
    if col == cols - 1:
        loop += '</div>'

    col = (col + 1) % cols

loop += '</div>'

bottom = '<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script></body></html>'

page = HTMLBeautifier.beautify(top + loop + bottom)

f = open("index.html", "w")
f.write(page)
f.close()
Пример #24
0
def generator():
    gen_code = str(HTMLBeautifier.beautify(boiler, 4))
    return str(gen_code)
Пример #25
0
import requests
from bs4 import BeautifulSoup as bs
from html5print import HTMLBeautifier
import lxml
import webbrowser

reqses = requests.session()

google_main = reqses.get(url='http://google.com')

google_main.headers

print(HTMLBeautifier.beautify(google_main.content, 'lxml'))

soup = bs(google_main.content, 'html.parser')
print(soup.prettify())
Пример #26
0
suchbegriff = input(
    'Nach welchem Suchbegriff möchten sie auf Youtube live suchen?\n').lower()

url = 'http://www.youtube.com/results?search_query=' + suchbegriff + '&sp=EgJAAQ%253D%253D'
print(url)

headers = {
    'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'
}

scrape = requests.get(url, headers=headers, timeout=999)

output = open('output.txt', 'w+', encoding="utf8")
beautify = HTMLBeautifier.beautify(scrape.text, 4)
output.write(beautify)
output.close()

videoId = []

with open('output.txt', 'r', encoding="utf8") as f:
    data = f.readlines()
    for ids in data:
        if '"addedVideoId": "' in ids:
            videoId.append(ids)

###FINAL###

print(f'\nDie {suchbegriff} ID`s lauten: \n')
print(''.join(videoId).replace(' ',
Пример #27
0
def generateTemplates():
    """
        Generate all templates.
    """
    global MODE
    start_time = datetime.now()

    pool = Pool(7)

    global templateData
    global templateParametersPredefined

    templatesEntrypoints = {}
    templatePathsList = os.listdir(config['TEMPLATES_DIRECTORY'])

    try:

        templateGlobalDataGenerator = None

        print(f'[?] Look for templates inside {config["TEMPLATES_DIRECTORY"]}')
        bar = Bar(f'Searching directories...', max=len(templatePathsList))

        for templatePath in templatePathsList:
            if os.path.isdir(
                    f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}'):
                if os.path.isfile(
                        f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}/index.html'
                ) or os.path.isfile(
                        f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}/index.py'
                ):
                    #
                    # This loop tries to find all html/js/css/py files.
                    #

                    templatesEntrypointsConfigPy = None
                    templatesEntrypointsJS = None
                    templatesEntrypointsCSS = None

                    if os.path.isfile(
                            f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}/index.py'
                    ):
                        templatesEntrypointsConfigPy = f'{config["TEMPLATES_PACKAGE"]}.{templatePath}.index'

                    if os.path.isfile(
                            f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}/index.js'
                    ):
                        templatesEntrypointsJS = f'{templatePath}/index.js'

                    if os.path.isfile(
                            f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}/index.css'
                    ):
                        templatesEntrypointsCSS = f'{templatePath}/index.css'

                    templateInputPath = f'{templatePath}/index.html'

                    if not os.path.isfile(
                            f'{config["TEMPLATES_DIRECTORY"]}/{templatePath}/index.html'
                    ):
                        if os.path.isfile(
                                f'{config["TEMPLATES_DIRECTORY"]}/index.html'):
                            templateInputPath = 'index.html'

                    templatesEntrypoints[f'{templatePath}/index.html'] = {
                        'input':
                        templateInputPath,
                        'inputLocation':
                        f'{templatePath}',
                        'output':
                        f'{config["OUTPUT_DIRECTORY"]}/{templatePath}.html',
                        'outputPrefix':
                        f'{config["OUTPUT_DIRECTORY"]}/{templatePath}',
                        'outputPostfix':
                        f'.html',
                        'isGlobal':
                        False,
                        'configPy':
                        templatesEntrypointsConfigPy,
                        'inputJS':
                        templatesEntrypointsJS,
                        'inputCSS':
                        templatesEntrypointsCSS,
                        'outputJS':
                        f'{config["OUTPUT_DIRECTORY"]}/{templatePath}.js',
                        'outputJSPrefix':
                        f'{config["OUTPUT_DIRECTORY"]}/{templatePath}_',
                        'outputJSPostfix':
                        f'.js',
                        'outputCSS':
                        f'{config["OUTPUT_DIRECTORY"]}/{templatePath}.css'
                    }
            bar.next()
        bar.finish()

        #
        # Find global top-level css/js/html/py file.
        #
        if os.path.isfile(f'{config["TEMPLATES_DIRECTORY"]}/index.html'):
            templatesEntrypointsConfigPy = None
            templatesEntrypointsJS = None
            templatesEntrypointsCSS = None

            if os.path.isfile(f'{config["TEMPLATES_DIRECTORY"]}/index.js'):
                templatesEntrypointsJS = f'index.js'

            if os.path.isfile(f'{config["TEMPLATES_DIRECTORY"]}/index.css'):
                templatesEntrypointsCSS = f'index.css'

            if os.path.isfile(f'{config["TEMPLATES_DIRECTORY"]}/index.py'):
                print('[i] Prepare global DataGenerator...')

                templateConfigModule = importlib.import_module(
                    f'{config["TEMPLATES_PACKAGE"]}.index')
                templateConfigModule = importlib.reload(templateConfigModule)

                templateGlobalDataGenerator = templateConfigModule.DataGenerator(
                    f'{config["TEMPLATES_DIRECTORY"]}/index.html', config)

                templateDataPrepared = templateGlobalDataGenerator.prepareData(
                    templateData, 'default', 0)
                if templateDataPrepared is not None:
                    templateData = templateDataPrepared

                print('[i] Save global DataGenerator...')

            templatesEntrypoints[f'index.html'] = {
                'input': 'index.html',
                'inputLocation': f'.',
                'output': f'{config["OUTPUT_DIRECTORY"]}/index.html',
                'outputPrefix': f'{config["OUTPUT_DIRECTORY"]}/index',
                'outputPostfix': f'.html',
                'configPy': None,
                'isGlobal': True,
                'inputJS': templatesEntrypointsJS,
                'inputCSS': templatesEntrypointsCSS,
                'outputJS': f'{config["OUTPUT_DIRECTORY"]}/index.js',
                'outputJSPrefix': f'{config["OUTPUT_DIRECTORY"]}/',
                'outputJSPostfix': f'.js',
                'outputCSS': f'{config["OUTPUT_DIRECTORY"]}/index.css'
            }

        pathlib.Path(config['OUTPUT_DIRECTORY']).mkdir(parents=True,
                                                       exist_ok=True)

        print(f'[i] Found {len(templatesEntrypoints)} subpage/-s templates.')

        print('[i] Generate templates...')
        for templateID, templateConfig in templatesEntrypoints.items():
            templateInputPath = templateConfig['input']
            templateInputLocation = templateConfig['inputLocation']
            templateOutputPath = templateConfig['output']
            templateOutputPrefix = templateConfig['outputPrefix']
            templateOutputPostfix = templateConfig['outputPostfix']
            templateConfigPy = templateConfig['configPy']
            templateConfigModule = None

            if templateConfigPy is not None:
                templateConfigModule = importlib.import_module(
                    templateConfigPy)
                templateConfigModule = importlib.reload(templateConfigModule)

            print(
                f'    * Generate template {templateInputPath} -> {templateOutputPath}'
            )
            jinjaEnv = Environment(
                loader=FileSystemLoader(config['TEMPLATES_DIRECTORY']),
                autoescape=select_autoescape(['html', 'xml']))

            templateParameters = {
                **templateData,
                **templateParametersPredefined
            }

            templateDataGenerator = None
            generatorScoped = None

            if templateConfigModule is not None:
                print(f'        - Load DataGenerator...')
                templateDataGenerator = templateConfigModule.DataGenerator(
                    templateInputPath, config, templateGlobalDataGenerator)
                print(f'        - Loaded DataGenerator')

            generatorScoped = templateDataGenerator
            if templateConfig['isGlobal']:
                generatorScoped = templateGlobalDataGenerator

            template = jinjaEnv.get_template(templateInputPath)

            if templateDataGenerator is None:
                with open(templateOutputPath, 'wb') as out:
                    out.write(
                        HTMLBeautifier.beautify(
                            template.render(**templateParameters),
                            4).encode('utf-8'))
            elif not hasattr(templateDataGenerator, 'getFileNames'):
                templateParametersPrepared = templateDataGenerator.prepareData(
                    templateParameters, 'default', 0)
                if templateParametersPrepared is not None:
                    templateParameters = templateParametersPrepared

                with open(templateOutputPath, 'wb') as out:
                    out.write(
                        HTMLBeautifier.beautify(
                            template.render(**templateParameters),
                            4).encode('utf-8'))
            else:

                renderSubtemplates(pool, templateID, templateOutputPrefix,
                                   templateOutputPostfix, templateInputPath,
                                   templateDataGenerator, templateParameters)

            if ((templateConfig['inputJS'] is not None) and
                (templateConfig['outputJS'] is not None)) or (hasattr(
                    templateDataGenerator, 'getJSFileNames')):

                JSfilelist = []

                if ((templateConfig['inputJS'] is not None)
                        and (templateConfig['outputJS'] is not None)):
                    JSfilelist = [{
                        'name': 'default',
                        'input': templateConfig['inputJS'],
                        'output': templateConfig['outputJS']
                    }]

                if hasattr(generatorScoped, 'getJSFileNames'):
                    print('        - Detected additional JS modules')
                    JSNames = generatorScoped.getJSFileNames()
                    for name in JSNames:
                        JSfilelist.append({
                            'name':
                            name,
                            'input':
                            f'{templateInputLocation}/{name}.js',
                            'output':
                            f'{templateConfig["outputJSPrefix"]}{name}{templateConfig["outputJSPostfix"]}'
                        })

                for JSFile in JSfilelist:

                    outputJS = JSFile["output"]
                    inputJS = JSFile["input"]
                    name = JSFile["name"]

                    print(f'        - Generating JS module: {name}...')
                    template = jinjaEnv.get_template(inputJS)
                    print(f'            -> Render module')
                    renderedModule = template.render(**templateParameters)

                    with open(outputJS, 'wb') as out:
                        if MODE is 'release':
                            print(f'            -> Minify JS module')
                            out.write(jsmin(renderedModule).encode('utf-8'))
                        else:
                            print(f'            -> Save JS module')
                            out.write((renderedModule).encode('utf-8'))

            if (templateConfig['inputCSS']
                    is not None) and (templateConfig['outputCSS'] is not None):
                print(f'        - Generate CSS...')
                template = jinjaEnv.get_template(templateConfig['inputCSS'])
                print(f'        - Save CSS...')
                with open(templateConfig['outputCSS'], 'wb') as out:
                    out.write(
                        template.render(**templateParameters).encode('utf-8'))
    except:
        print(f'[!] Unexpected error: {sys.exc_info()[0]}')

    time_elapsed = datetime.now() - start_time
    pool.close()
    print('[#] Done in (hh:mm:ss.ms) {}'.format(time_elapsed))
Пример #28
0
def prettify(raw_html):
    soup = bs4.BeautifulSoup(raw_html, 'html.parser')
    pretty1 = soup.prettify(encoding='utf-8')
    return HTMLBeautifier.beautify(pretty1, 4)
Пример #29
0
def generate(file):
    """
    Method to generate the HTML given an ot-tableau tableau.
    :param file: a text file containing only the text of the tableau
    :return: the HTML as a string, prettified with html5print
    """
    lines: List[str]
    with open(file) as f:
        lines = [line for line in f]
    terms = get_commands(lines)

    inp = [
        get_args_from_command(term)[1] for term in terms
        if term.__contains__("inp")
    ][0]
    constraints = [
        get_args_from_command(term)[1] for term in terms
        if term.__contains__("const")
    ]
    candidates = [
        get_args_from_command(term) for term in terms
        if term.__contains__("cand")
    ]
    viols = [
        get_args_from_command(term)[1] for term in terms
        if term.__contains__("vio")
    ]

    viol_dict = defaultdict(list)
    span = 0
    for cand in candidates:
        viol_dict[cand[1]].extend(viols[span:span + len(constraints)])
        span += len(constraints)

    html = [
        "<!DOCTYPE html><meta charset='UTF8'><html lang='en'><head><style>",
        CSS, "</style>", "<title></title>",
        "</head><body><table class='outer'>", "</table></body></html>"
    ]

    tableau_format = ""
    for i, j in enumerate(difflib.ndiff(lines[0], "\\begin{tableau}{}")):
        if j[0] == '-':
            tableau_format += j[2]

    ranking_info = tableau_format.split('c')[1:]

    html.insert(-1, "<tr><td class='outer'><table class='in'><thead><tr>")
    html.insert(-1, "<th class='input' colspan='2'>" + inp + "</th>")
    html.insert(-1, "</tr></thead><tbody class='noshow'>")

    candidate_column = ""
    for candidate in candidates:
        candidate_column += "<tr class='candidate'>"
        candidate_column += "<td class='indicator'>"
        if candidate[0]:
            to_insert = CHAR_DICT[candidate[0]] if CHAR_DICT[
                candidate[0]] else "ERR"
            candidate_column += to_insert
        candidate_column += "</td>"
        candidate_column += "<td class='candidate'>" + candidate[1] + "</td>"
        candidate_column += "</tr>"
    html.insert(-1, candidate_column)
    html.insert(-1, "</tbody></table></td>")
    html.insert(-1, "<td class='outer'><table class='const'><tr>")

    constraint_row = ""
    for i in range(len(constraints)):
        if ranking_info[i] == ':':
            constraint_row += "<th class='constraint unranked'>" + constraints[
                i] + "</th>"
        else:
            constraint_row += "<th class='constraint'>" + constraints[
                i] + "</th>"

    html.insert(-1, constraint_row)
    html.insert(-1, "</tr></table></td></tr>")

    html.insert(
        -1, "<tr><td class='outer'><table class='cand'>" +
        "<tr class='noshow'></tr>" + candidate_column)
    html.insert(-1, "</table></td>")
    html.insert(-1,
                "<td class='outer'><table class='viol'><tr class='noshow'>")
    html.insert(-1, constraint_row)
    html.insert(-1, "</tr>")

    for candidate in candidates:
        html.insert(-1, "<tr>")
        for i in range(len(viol_dict[candidate[1]])):
            if ranking_info[i] == ':':
                html.insert(
                    -1, "<td class='vio unranked'>" +
                    viol_dict[candidate[1]][i] + "</td>")
            else:
                html.insert(
                    -1,
                    "<td class='vio'>" + viol_dict[candidate[1]][i] + "</td>")
        html.insert(-1, "</tr>")

    html.insert(-1, "</table></td></tr>")
    return HTMLBeautifier.beautify("".join(html), 4)
def print_html5(html):
    print(HTMLBeautifier.beautify(html, 4))
Пример #31
0
def generate_table(output_object: List, doc_list: List[str]) -> str:
    """
    Generates an html table from a report object
    Parameters
    ----------
    output_object: List
        Data object to generate report from
    doc_list: List[str]
        List of documents that were scanned
        
    Returns
    -------
    result: str
        Output html string
    """

    doc_list = sorted(doc_list)

    header: str = """
    <html>
        <head>
        <link rel="stylesheet" href="styling.css">
    </head>
    <body>
        <h1>Keyword extraction</h1>
        <h2>Documents scanned:</h2>
        <ol>
    """

    doc_list_str: str = ""
    for item in doc_list:
        doc_list_str += f'<li><a href="{item}">{item}</a></li>'

    table_header: str = """
    </ol>
    <h2>Keyword list</h2>
    <table class="data-table">
        <tr>
            <th>Word stem (Words)</th>
            <th>Total sentence occurrences</th>
            <th>Documents</th>
            <th>Sentences containing the words</th>
        </tr>
    """

    table_items: List[str] = []

    for entry in output_object:
        word_list: str = ", ".join(entry["words"])
        entry_doc_list: str = '<ul class="doclist">' + "\n".join(
            map(lambda x: f"<li>{x}</li>", sorted(
                entry["documents"]))) + "</ul>"

        sentence_map_keys = sorted(entry["sentences"].keys())

        sentence_list: str = ""
        for k in sentence_map_keys:
            sentence_list += f"<h3>{k}</h3>\n" + "\n".join(
                map(lambda x: highlight_keywords(x, entry["words"]),
                    entry["sentences"][k]))

        entry_output: str = f"""
        <tr>
            <td><span class = "highlight">{entry["stem"]}</span> ({word_list})</td>
            <td>{entry["sentence_count"]}</td>
            <td>{entry_doc_list}</td>
            <td>{sentence_list}</td>
        </tr>
        """
        table_items.append(entry_output)

    footer: str = """
    </table>
    </body>
    """

    output_str = header + doc_list_str + table_header + "\n".join(
        table_items) + footer

    return HTMLBeautifier.beautify(output_str, indent=2)
Пример #32
0
def format_description(data):
    if request.method == 'GET' and data:
        return HTMLBeautifier.beautify(data.text, 8)
    return data
Пример #33
0
baseline = [(f,
             readoutput(TEST_PATH + "results/" + splitext(f)[0] + ".xidv.out"),
             process(f))
            for f in listdir(BUNDLE_PATH) if isfile(join(BUNDLE_PATH, f))]

# sorting on first img, even if there are multiple images/bundle
sortimgs = sorted(baseline, key=lambda img: img[2][0][2])


data = [['h1',strftime("%Y-%m-%d %H:%M:%S", gmtime())],
        [[
        ['hr'],
        ['h1', x[0]],
        ['table',
         ['tr', ['td', x[1].replace("\n", "<br />")]],
         ['tr', [['td', ['h2', "expected"]], ['td', ['h2', "actual"]]]],
         [['tr',
          [['td', ['img', {'src': i[0]}]],
           ['td', ['img', {'src': i[1]}]]]]
             for i in x[2]]]]
        for x in sortimgs[::-1]]]

myhtml = html(data)

pretty = HTMLBeautifier.beautify(myhtml, 2)

f = open(TEST_PATH + 'compare.html', 'w')
f.write(pretty)
f.close()
Пример #34
0
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference("browser.helperApps.neverAsk.openFile","text/plain")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain")
profile.set_preference("browser.download.folderList", 2);
profile.set_preference('browser.download.dir', '/home/andrei')
profile.set_preference('browser.download.manager.showWhenStarting', False)

options = Options()
options.add_argument("--headless")

browser = webdriver.Firefox(firefox_profile=profile,firefox_options=options)
#browser.get("https://www.ebi.ac.uk/gxa/experiments/E-MTAB-5214/Results?ref=aebrowse")
browser.get("https://www.ebi.ac.uk/gxa/genes/ENSG00000169344?bs=%7B%22homo%20sapiens%22%3A%5B%22ORGANISM_PART%22%5D%7D&ds=%7B%22kingdom%22%3A%5B%22animals%22%5D%7D#baseline")
element=None
try:
    element = WebDriverWait(browser, 60).until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Download"]')))
except:
    print("Exception occured",file=sys.stderr)

#print(browser.page_source.encode("utf-8"))
print(HTMLBeautifier.beautify(browser.page_source.encode("utf-8").decode('ascii', 'ignore'),4))
element.click()
#print("Element clicked",file=sys.stderr)
time.sleep(5)
browser.quit()
Пример #35
0
                                        style="cursor:pointer;margin-top:3px;height:14.14px;width:8.5px;float:right",
                                    )

                            with tag("div", klass="card1"):
                                doc.stag(
                                    "img",
                                    src="FASTQ.png",
                                    style="cursor:pointer;height:20px;width:20px;float:left;margin-right:16px",
                                )
                                with tag("div", klass="text2", style="float:left"):
                                    text("TBR1448.read1_fastqc.html")
                                with tag("a", href="https://www.baidu.com/", target="_blank"):
                                    doc.stag(
                                        "img",
                                        src="Icon.png",
                                        style="cursor:pointer;margin-top:3px;height:14.14px;width:8.5px;float:right",
                                    )

# start html creat
doc, tag, text, line = Doc().ttl()
write_head(doc, tag, text, line)
write_body(doc, tag, text, line)

# write output to html
prettyHTML = HTMLBeautifier.beautify(indent(doc.getvalue()), 4)
# prettyHTML = indent(doc.getvalue())

fout = open("test.html", "w")
fout.write(prettyHTML)
fout.close()
Пример #36
0
 def getReport(self) -> bytes:
     return HTMLBeautifier.beautify(flat.flatten(self.tag).decode('charmap')).encode('charmap')