Exemplo n.º 1
0
def show_highlight(news, article_url):
    news = news.upper()
    article_url = articles.find_one({'title': article_url})['url']
    print(article_url)
    if news in known_news:
        #     article_url = 'https://www.foxnews.com/us/man-arrested-for-stabbing-baby-trump-protest-balloon-at-alabama-lsu-game'
        highlight(article_url, d)
        return render_template('highlighted_article.html')
    else:
        return '404'
Exemplo n.º 2
0
def color_palette(*args):
    """
    Prints out names, (hex and/or RGB and/or numerical values)
    for each of the web-safe HTML-supported colors, in color.
    """

    from highlight import highlight

    for color_name, hex_value in color_names.items():
        c = convert_color(hex_value, 'num')
        highlight(' ' + color_name + ' ',
                  c,
                  False,
                  fill='#',
                  width=42,
                  alignment='center')
        if 'hex' in args:
            highlight(hex_value, c, False, width=42, alignment='center')
        if 'rgb' in args:
            highlight(convert_color(hex_value, 'rgb'),
                      c,
                      False,
                      width=42,
                      alignment='center')
        if 'num' in args:
            highlight(convert_color(hex_value, 'num'),
                      c,
                      False,
                      width=42,
                      alignment='center')
Exemplo n.º 3
0
def call(name, args, wd=None):
    logger = logging.getLogger(highlight(name))
    logger.info("starting %s...", args)

    master, slave = pty.openpty()

    process = subprocess.Popen(args,
                               bufsize=1,
                               stdin=slave,
                               stdout=slave,
                               stderr=subprocess.STDOUT,
                               close_fds=True,
                               cwd=wd)
    os.close(slave)
    process.stdout = os.fdopen(master)
    try:
        while True:
            line = process.stdout.readline()
            if not line: break

            line = line.replace("\n", "")
            if "\r" in line:
                line = de_ret(line)
            logger.info(line)
    except IOError as e:
        if e.errno == 5:
            pass
        else:
            raise
    return process.wait()
Exemplo n.º 4
0
def _debug(model: models.Model, event: str):
    model = replace(model, mode=0)

    model_dict = asdict(model)
    model_dict.pop("debug_model_length")
    model_dict.pop("debug_model_text")

    # strip Escape sequences from highlighted content for readability
    for tab in model_dict['tabs']:
        if tab and not tab['selected_file']['is_dir']:
            tab['selected_file']['content'] = [
                blesses.strip_esc(line)
                for line in tab['selected_file']['content']
            ]

    model_json = json.dumps(model_dict, indent=2)

    if model.code_hilighting:
        model = replace(model,
                        debug_model_text=highlight(model_json,
                                                   "json").split("\n"))
    else:
        model = replace(model, debug_model_text=model_json.split("\n"))

    model = replace(
        model,
        debug_model_text=model.debug_model_text[0:len(model.debug_model_text) -
                                                1])

    model = replace(model, debug_model_length=len(model.debug_model_text))
    return model
Exemplo n.º 5
0
    def view(self):
        data = {
            "page": self._get_page_data(),
            "ctxnav": list(self.environ._ctxnav("view", self.name)),
        }

        data["html"] = highlight(data["page"]["text"], mime=self.mime)
        return self.render("view.html", **data)
    def show_results(self):
        """ show table of results"""

        doc['container'].clear()

        doc['container'] <= html.DIV(
            'Browser Version: %s' % window.navigator.userAgent)
        _v = sys.implementation.version
        doc['container'] <= html.DIV('Brython Version: %s.%s.%s' %
                                     (_v.major, _v.minor, _v.micro))
        doc['container'] <= html.DIV(
            'Brython debug mode: %s' % sys.brython_debug_mode)
        doc['container'] <= html.DIV(
            'CPython Version: %s' % self.cpython_version)

        doc['container'] <= html.P(html.I('Results are in milliseconds (ms)'))

        _table = html.TABLE()
        _tr = html.TR()
        _tr <= html.TH('Benchmark')
        _tr <= html.TH('Code')
        _tr <= html.TH('Brython')
        _tr <= html.TH('CPython')
        _tr <= html.TH('Difference')
        _tr <= html.TH('X Faster')
        _table <= _tr
        for _filename in self._timings.keys():
            _tr = html.TR()
            _tr <= html.TD(_filename)
            _tr <= html.TD(
                highlight.highlight(self._timings[_filename]['code']))
            for _platform in ('brython', 'cpython'):
                _tr <= html.TD('%5.0f' % self._timings[_filename][_platform],
                               style={'text-align': 'right'})

            _diff = self._timings[_filename]['cpython'] - self._timings[
                _filename]['brython']
            _x = self._timings[_filename]['cpython'] / self._timings[
                _filename]['brython']

            if _x > 1:
                _color = "green"
            elif _x < 0.5:
                _color = "red"
            else:
                _color = "black"
            _tr <= html.TD('%5.0f' % _diff, style={'text-align': 'right'})
            _tr <= html.TD('%4.2f' % _x,
                           style={
                               'color': _color,
                               'text-align': 'right'
                           })
            _table <= _tr

        doc['container'] <= _table
Exemplo n.º 7
0
def show_page(slideshow, zone, page_num):
    # if table of contents is not empty, add it
    if slideshow.contents:
        toc = html.SELECT(name="toc")
        toc.bind(
            'change', lambda ev: show_page(
                slideshow, zone,
                int(ev.target.options[ev.target.selectedIndex].value)))
        for content in slideshow.contents:
            toc <= html.OPTION(
                content[0], value=content[1], selected=page_num >= content[1])

    slideshow.page_num = int(page_num)

    # store page num in a cookie
    document.cookie = "page={}".format(page_num)

    zone.clear()

    body = html.DIV()
    body.html = markdown.mark(slideshow.pages[page_num])[0]

    if slideshow.contents:
        body = html.DIV(toc + body)

    footer = html.DIV(Id="footer")
    if slideshow.title:
        footer <= html.DIV(slideshow.title, style=dict(display='inline'))
    if slideshow.show_page_num:
        footer <= html.SPAN(' (%s/%s)' % (page_num + 1, len(slideshow.pages)),
                            style=dict(display='inline'))
    timeline = html.DIV(Id='timeline')
    tl_pos = html.DIV(Id='tl_pos')
    timeline <= tl_pos
    timeline.bind('click', lambda ev: move_to(ev, slideshow, zone))
    tl_pos.bind('click', click_on_tl_pos)
    zone <= body + footer + timeline
    wh = window.innerHeight
    footer.style.top = "{}px".format(int(wh * 0.9))
    timeline.style.top = "{}px".format(int(wh * 0.85))
    tl_pos.style.left = '%spx' % (timeline.width * page_num /
                                  len(slideshow.pages))
    document["cours"].style.minHeight = "{}px".format(int(wh * 0.8))

    for elt in zone.get(selector='.python'):
        src = elt.text.strip()
        width = max(len(line) for line in src.split('\n'))
        width = max(width, 30)
        # replace element content by highlighted code
        elt.html = highlight.highlight(src).html
        elt.style.width = '%sem' % int(0.7 * width)
        elt.bind('click', run_code)
Exemplo n.º 8
0
 def xml(self):
     language = self['language'] or 'PYTHON'
     link = self['link']
     counter = self.attributes.get('counter', 1)
     styles = self['styles'] or {}
     return highlight(
         ''.join(self.components),
         language=language,
         link=link,
         counter=counter,
         styles=styles,
         attributes=self.attributes,
     )
Exemplo n.º 9
0
 def xml(self):
     language = self['language'] or 'PYTHON'
     link = self['link']
     counter = self.attributes.get('counter', 1)
     styles = self['styles'] or {}
     return highlight(
         ''.join(self.components),
         language=language,
         link=link,
         counter=counter,
         styles=styles,
         attributes=self.attributes,
         )
Exemplo n.º 10
0
def load(url, target):
    # fake query string to bypass browser cache
    qs = "?foo=%s" % time.time()
    try:
        mk, scripts = markdown.mark(open(url + qs).read())
    except IOError:
        doc[target].html = "Page %s not found" % url
        return False
    doc[target].html = mk
    for script in scripts:
        exec(script)
    for elt in doc[target].get(selector=".exec"):
        # Python code executed when user clicks on a button
        elt.contentEditable = True
        src = elt.text.strip()
        h = highlight.highlight(src)
        h.className = "pycode"
        elt.clear()
        elt <= h
        elt.focus()
        btn = html.BUTTON("▶")
        btn.bind("click", run)
        elt.parent.insertBefore(btn, elt)
    for elt in doc[target].get(selector=".exec_on_load"):
        # Python code executed on page load
        src = elt.text.strip()
        h = highlight.highlight(src)
        h.className = "pycode"
        elt.clear()
        elt <= h
        exec(src)
    for elt in doc[target].get(selector=".python"):
        src = elt.text.strip()
        h = highlight.highlight(src)
        h.className = "pycode"
        elt.clear()
        elt <= h
    return False
Exemplo n.º 11
0
def load(url, target):
    # fake query string to bypass browser cache
    qs = '?foo=%s' % time.time()
    try:
        mk, scripts = markdown.mark(open(url + qs).read())
    except IOError:
        doc[target].html = "Page %s not found" % url
        return False
    doc[target].html = mk
    for script in scripts:
        exec(script)
    for elt in doc[target].get(selector='.exec'):
        # Python code executed when user clicks on a button
        elt.contentEditable = True
        src = elt.text.strip()
        h = highlight.highlight(src)
        h.className = "pycode"
        elt.clear()
        elt <= h
        elt.focus()
        btn = html.BUTTON('▶')
        btn.bind('click', run)
        elt.parent.insertBefore(btn, elt)
    for elt in doc[target].get(selector='.exec_on_load'):
        # Python code executed on page load
        src = elt.text.strip()
        h = highlight.highlight(src)
        h.className = "pycode"
        elt.clear()
        elt <= h
        exec(src)
    for elt in doc[target].get(selector='.python'):
        src = elt.text.strip()
        h = highlight.highlight(src)
        h.className = "pycode"
        elt.clear()
        elt <= h
    return False
Exemplo n.º 12
0
def main():
    for file_name in ("main.py", "highlight.py",
                      "lexer.py"):  # opens the files and prints them
        with open(file_name, 'r') as f:
            code = f.read()
            print("File: " + file_name)
            skip_pos, highlights = highlight.highlight(highlight.parse(code))

            i = 0

            while i < len(highlights):
                c = highlights[i]
                print(c, end='', flush=True)
                time.sleep(0.05)
                i += 1
Exemplo n.º 13
0
  def show_results(self):
      """ show table of results"""

      doc['container'].clear()

      doc['container'] <= html.DIV('Browser Version: %s' % window.navigator.userAgent)
      _v=sys.implementation.version
      doc['container'] <= html.DIV('Brython Version: %s.%s.%s' % (_v.major, _v.minor, _v.micro))
      doc['container'] <= html.DIV('Brython debug mode: %s' % sys.brython_debug_mode)
      doc['container'] <= html.DIV('CPython Version: %s' % self.cpython_version)

      doc['container'] <= html.P(html.I('Results are in milliseconds (ms)'))

      _table=html.TABLE()
      _tr=html.TR()
      _tr <= html.TH('Benchmark')
      _tr <= html.TH('Code')
      _tr <= html.TH('Brython')
      _tr <= html.TH('CPython')
      _tr <= html.TH('Difference')
      _tr <= html.TH('X Faster')
      _table <= _tr
      for _filename in self._timings.keys():
          _tr=html.TR()
          _tr <= html.TD(_filename)
          _tr <= html.TD(highlight.highlight(self._timings[_filename]['code']))
          for _platform in ('brython', 'cpython'):
              _tr <= html.TD('%5.0f' % self._timings[_filename][_platform],
                             style={'text-align':'right'})

          _diff=self._timings[_filename]['cpython'] - self._timings[_filename]['brython']
          _x=self._timings[_filename]['cpython']/self._timings[_filename]['brython']

          if _x > 1:
             _color="green"
          elif _x < 0.5:
             _color="red"
          else:
             _color="black"
          _tr <= html.TD('%5.0f' % _diff,
                         style={'text-align':'right'})
          _tr <= html.TD('%4.2f' % _x, 
                         style={'color': _color, 
                                'text-align':'right'})
          _table <= _tr

      doc['container'] <= _table
Exemplo n.º 14
0
def search(course_name, keyword):
    files = glob('./data/*')
    filename = sorted(files)[-1]
    crawling_time = re.search(r'[0-9]{10}', filename).group()
    with open(filename, 'rb') as f:
        tree = pickle.load(f)
        data = {}
        data['results'] = []
        data['crawling_time'] = crawling_time
        for pre, fill, node in tree:
            if hasattr(node, 'content') and node.parent.name == course_name:
                res = highlight(node.content, keyword)
                if len(res):
                    data['results'].append({
                        'highlights': res,
                        'url': node.url,
                        'title': node.name
                    })
        return data
Exemplo n.º 15
0
def hi_sentence(sent, features):
    locs = []
    ans = sent['annotation']
    lemmas = ans['lemma']
    posses = ans['pos']
    for ft in features:
        for lm in lemmas:
            ft_str = ft[:-2]
            ft_pos = ft[-1:]
            if lm['label'] == ft_str:

                def is_match(pos):
                    return ((pos['begin'] == lm['begin'])
                            and (pos['label'][0] == ft_pos))

                # at most one, of course...
                for p in filter(is_match, posses):
                    loc = int(p['begin']), int(p['length'])
                    locs.append(loc)
    return highlight(sent['display'], locs, 'green')
Exemplo n.º 16
0
def hi_sentence(sent, features):
    locs = []
    ans = sent['annotation']
    lemmas = ans['lemma']
    posses = ans['pos']
    for ft in features:
        for lm in lemmas:
            ft_str = ft[:-2]
            ft_pos = ft[-1:]
            if lm['label'] == ft_str:
                def is_match(pos):
                    return (
                        (pos['begin'] == lm['begin']) and
                        (pos['label'][0] == ft_pos)
                        )
                # at most one, of course...
                for p in filter(is_match, posses):
                    loc = int(p['begin']), int(p['length'])
                    locs.append(loc)
    return highlight(sent['display'], locs, 'green')
Exemplo n.º 17
0
def show_page(slideshow, zone, page_num):
    # if table of contents is not empty, add it
    if slideshow.contents:
        toc = html.SELECT(name="toc")
        toc.bind('change', lambda ev: show_page(slideshow, zone, 
            int(ev.target.options[ev.target.selectedIndex].value)))
        for content in slideshow.contents:
            toc <= html.OPTION(content[0], value=content[1],
                selected=page_num>=content[1])

    slideshow.page_num = int(page_num)
    zone.clear()
            
    body = html.DIV()
    body.html = markdown.mark(slideshow.pages[page_num])[0]

    if slideshow.contents:
        body = html.DIV(toc+body)

    footer = html.DIV(Id="footer")
    if slideshow.title:
        footer <= html.DIV(slideshow.title,style=dict(display='inline'))
    if slideshow.show_page_num:
        footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(slideshow.pages)),
            style=dict(display='inline'))
    timeline = html.DIV(Id='timeline')
    tl_pos = html.DIV(Id='tl_pos')
    timeline <= tl_pos
    timeline.bind('click', lambda ev:move_to(ev, slideshow, zone))
    tl_pos.bind('click', click_on_tl_pos)
    zone <= body+footer+timeline
    tl_pos.style.left = '%spx' %(timeline.width*page_num/len(slideshow.pages))
    
    for elt in zone.get(selector='.python'):
        src = elt.text.strip()
        width = max(len(line) for line in src.split('\n'))
        # replace element content by highlighted code
        elt.html = highlight.highlight(src).html
        elt.style.width = '%sem' %int(0.7*width)
Exemplo n.º 18
0
    def diff(self, *args, **kwargs):
        name = os.path.sep.join(args)

        rev = kwargs["rev"]

        to_rev = int(rev)
        from_rev = to_rev - 1

        text = self.storage.revision_text(name, from_rev).split("\n")
        other = self.storage.revision_text(name, to_rev).split("\n")

        to_date = ""
        from_date = ""
        date_format = "%Y-%m-%dT%H:%M:%SZ"

        for history in self.storage.page_history(name):
            if history[0] == to_rev:
                to_date = history[1]
            elif history[0] == from_rev:
                from_date = history[1]

        if not from_date:
            from_date = to_date

        diff = "\n".join(
            unified_diff(text, other, "%s@%d" % (name, from_rev),
                         "%s@%d" % (name, to_rev),
                         strftime(date_format, gmtime(from_date)),
                         strftime(date_format, gmtime(to_date))))

        data = {
            "title": "diff of %s from %s to %s" % (name, from_rev, to_rev),
            "diff": highlight(diff, lang="diff"),
        }

        return self.render("diff.html", **data)
Exemplo n.º 19
0
    def diff(self, *args, **kwargs):
        name = os.path.sep.join(args)

        rev = kwargs["rev"]

        to_rev = int(rev)
        from_rev = to_rev - 1

        text = self.storage.revision_text(name, from_rev).split("\n")
        other = self.storage.revision_text(name, to_rev).split("\n")

        to_date = ""
        from_date = ""
        date_format = "%Y-%m-%dT%H:%M:%SZ"

        for history in self.storage.page_history(name):
            if history[0] == to_rev:
                to_date = history[1]
            elif history[0] == from_rev:
                from_date = history[1]

        if not from_date:
            from_date = to_date

        diff = "\n".join(unified_diff(text, other,
            "%s@%d" % (name, from_rev),
            "%s@%d" % (name, to_rev),
            strftime(date_format, gmtime(from_date)),
            strftime(date_format, gmtime(to_date))))

        data = {
            "title": "diff of %s from %s to %s" % (name, from_rev, to_rev),
            "diff": highlight(diff, lang="diff"),
        }

        return self.render("diff.html", **data)
Exemplo n.º 20
0
lines = []
tokens = []


def match(query, line):
    return all(w in line for w in query)


def search(q):
    return [line for line in tokens if match(q, line)]


for line in open('tokenized_quotes.txt'):
    L = line.split()
    tokens.append(L)

print('No, dalej!')

t0 = time.time()

for x in sys.stdin:
    L = x.split()
    print(green('QUERY: ') + ' '.join(L))
    search(L)
    for res in search(L):
        print('   ', highlight(L, res))
    yellow_line()
    print()
print(time.time() - t0)
Exemplo n.º 21
0
def simulate_console_statement(varname,
                               function=None,
                               args=[],
                               assign='',
                               module=None,
                               comment=None):
    highlight('>>> ' + varname + ' = ', 'white')
    if module:
        print module + '.',
    if function:
        highlight(function, 'orange')
        highlight('(', 'white')
        if args:
            if str.isdigit(str(args[0])) or isinstance(args[0], (int, float)):
                highlight(args[0], 'yellow')
            else:
                try:
                    args[0].index('=')
                    l, r = args[0].split('=')
                    highlight(l + '=', 'white')
                    if str.isdigit(r):
                        highlight(r, 'yellow')
                    else:
                        highlight(r, 'green')
                except:
                    highlight(args[0], 'green')
            for each in args[1:]:
                highlight(', ', 'white')
                if str.isdigit(str(each)):
                    highlight(each, 'yellow')
                else:
                    try:
                        each.index('=')
                        l, r = each.split('=')
                        highlight(l + '=', 'white')
                        if str.isdigit(r):
                            highlight(r, 'yellow')
                        else:
                            highlight(r, 'green')
                    except:
                        highlight(args[0], 'green')
        highlight(')', 'white')
    elif assign:
        if isinstance(assign, (int, float)):
            highlight(assign, 'yellow')
        else:
            highlight(assign, 'green')
    if comment:
        highlight(' # ' + comment, 'gray')
    print
Exemplo n.º 22
0
def simulate_console_function(function, args, module=MODULE, comment=None):
    highlight('>>> ' + module + '.', 'white')
    highlight(function, 'orange')
    highlight('(', 'white')
    if args:
        if str.isdigit(str(args[0])) or isinstance(args[0], (int, float)):
            highlight(args[0], 'yellow')
        else:
            try:
                args[0].index('=')
                l, r = args[0].split('=')
                highlight(l + '=', 'white')
                if str.isdigit(r):
                    highlight(r, 'yellow')
                else:
                    highlight(r, 'green')
            except:
                highlight(args[0], 'green')
        for each in args[1:]:
            highlight(', ', 'white')
            if str.isdigit(str(each)):
                highlight(each, 'yellow')
            else:
                try:
                    each.index('=')
                    l, r = each.split('=')
                    highlight(l + '=', 'white')
                    if str.isdigit(r):
                        highlight(r, 'yellow')
                    else:
                        highlight(r, 'green')
                except:
                    highlight(args[0], 'green')
        highlight(')', 'white')
    if comment:
        highlight(' # ' + comment, 'gray')
    print
Exemplo n.º 23
0
def border():
    highlight('*' * 42, 'blue', False)
Exemplo n.º 24
0
                        else:
                            highlight(r, 'green')
                    except:
                        highlight(args[0], 'green')
        highlight(')', 'white')
    elif assign:
        if isinstance(assign, (int, float)):
            highlight(assign, 'yellow')
        else:
            highlight(assign, 'green')
    if comment:
        highlight(' # ' + comment, 'gray')
    print


highlight('- formatlib.numbers -'.center(42), 'green', False)
print

border()

print fl.zero_lead.__doc__

simulate_console_function('zero_lead', [2], comment=fl.zero_lead(2))
simulate_console_function('zero_lead', [12], comment=fl.zero_lead(12))
simulate_console_function('zero_lead', [2, 3], comment=fl.zero_lead(2, 3))

print

border()

print fl.zero_trail.__doc__
Exemplo n.º 25
0
def show_page(slideshow, zone, page_num):
    # if table of contents is not empty, add it
    if slideshow.contents:
        toc = html.SELECT(name="toc")
        toc.bind('change', lambda ev: show_page(slideshow, zone, 
            int(ev.target.options[ev.target.selectedIndex].value)))
        for content in slideshow.contents:
            toc <= html.OPTION(content[0], value=content[1],
                selected=page_num>=content[1])

    slideshow.page_num = int(page_num)
    
    # store page num in a cookie
    document.cookie = "page={}".format(page_num)

    zone.clear()
    
    body = html.DIV()
    body.html = markdown.mark(slideshow.pages[page_num])[0]
    
    if slideshow.contents:
        body = html.DIV(toc + body)

    footer = html.DIV(Id="footer")
    if slideshow.title:
        footer <= html.DIV(slideshow.title,style=dict(display='inline'))
    if slideshow.show_page_num:
        footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(slideshow.pages)),
            style=dict(display='inline'))
    timeline = html.DIV(Id='timeline')
    tl_pos = html.DIV(Id='tl_pos')
    timeline <= tl_pos
    timeline.bind('click', lambda ev:move_to(ev, slideshow, zone))
    tl_pos.bind('click', click_on_tl_pos)
    zone <= body + footer +timeline
    wh = window.innerHeight
    footer.style.top = "{}px".format(int(wh * 0.9))
    timeline.style.top = "{}px".format(int(wh * 0.85))
    tl_pos.style.left = '%spx' %(timeline.width*page_num/len(slideshow.pages))
    document["cours"].style.minHeight = "{}px".format(int(wh * 0.8))
    
    for elt in zone.get(selector='.python'):
        src = elt.text.strip()
        width = max(len(line) for line in src.split('\n'))
        width = max(width, 30)
        # replace element content by highlighted code
        elt.html = highlight.highlight(src).html
        elt.style.width = '%sem' %int(0.7*width)
        elt.bind('click', run_code)

    for elt in zone.get(selector='.python-console'):
        src = elt.text.strip()
        lines = src.split('\n')
        result = ''
        py = ''
        py_starts = []
        for line in lines:
            if line.startswith('>>>') or line.startswith('...'):
                py += line[4:]+'\n'
                py_starts.append('<span class="python-prompt">{}</span>'.format(line[:3]))
            else:
                if py:
                    colored = highlight.highlight(py).html
                    colored_lines = colored.split('\n')
                    if result:
                        result += '\n'
                    result += '\n'.join(start+' '+line
                        for (start, line) in zip(py_starts, colored_lines))
                    py = ''
                    py_starts = []
                result += '\n' + line
        if py:
            colored = highlight.highlight(py).html
            colored_lines = colored.split('\n')
            if result:
                result += '\n'
            result += '\n'.join(start+' '+line
                for (start, line) in zip(py_starts, colored_lines))
            py = ''
            py_starts = []

        elt.html = result
Exemplo n.º 26
0
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

browser = webdriver.Chrome()

FirstName = "Phoenix"
LastName = "Wright"
Email = "*****@*****.**"
PassWord = "******"

browser.get('https://courses.ultimateqa.com/users/sign_in')

elem = browser.find_element_by_link_text('Create a new account')

highlight.highlight(elem)  #highlights link about to be clicked

browser.implicitly_wait(5)
elem.click()

elem = browser.find_element_by_id('user_first_name')
elem.send_keys(FirstName)
elem = browser.find_element_by_id('user_last_name')
elem.send_keys(LastName)
elem = browser.find_element_by_id('user_email')
elem.send_keys(Email)
elem = browser.find_element_by_id('user_password')
elem.send_keys(PassWord + Keys.ENTER)

#copied
print()
Exemplo n.º 27
0
def analyze():
    start = time.time()
    # Receives the input query from form
    if request.method == 'POST':
        '''global rawtext
		global phrases
		global important
		global bold'''
        rawtext = request.form['rawtext']
        # Analysis
        docx = nlp(rawtext)
        phrases = extract.phrases(rawtext)

        important = extract.important(rawtext)
        important = list(set(important))
        bold = extract.bold(rawtext)
        bold = list(set(bold))
        # Tokens
        custom_tokens = [token.text for token in docx]
        #print(custom_tokens)
        #print(bold)
        #print(important)
        #print('\n\n')
        #print(phrases)
        text = highlight.highlight(rawtext, phrases, bold, important)
        print(text)

        initial = """
		<html>
		<head>
		<title>Text Highlighted</title>
		<style>
			a { color: #ff6600; transition: .5s; -moz-transition: .5s; -webkit-transition: .5s; -o-transition: .5s; font-family: 'Muli', sans-serif; }


a:hover { text-decoration: underline }


h1 { padding-bottom: 15px }


h1 a { font-family: 'Open Sans Condensed', sans-serif; font-size: 48px; color: #333; }


h1 a:hover { color: #ff6600; text-decoration: none; }


p { color: #333; font-family: 'Muli', sans-serif; margin-bottom: 15px; }


a.more-link { color: white; font-weight: bold; font-size: 14px; font-family: Arial, Helvetica, sans-serif; padding: 3px 10px; background-color: #ff6600; border-radius: 5px; float: right; }


a.more-link:hover { text-decoration: none; background-color: #666; border-radius: 0px; }
		</style>
		</head>
		<body>
		<p>"""
        towrite = initial + text + """</p></body></html"""
        f = open('templates/doc.html', 'w', encoding="utf8")
        f.write(towrite)
        f.close()
        print(text)
        f = open('text.txt', 'w')
        f.write(rawtext)
        f.close()
        # Word Info
        custom_wordinfo = [(token.text, token.lemma_, token.shape_,
                            token.is_alpha, token.is_stop) for token in docx]
        custom_postagging = [(word.text, word.tag_, word.pos_, word.dep_)
                             for word in docx]
        # NER
        custom_namedentities = [(entity.text, entity.label_)
                                for entity in docx.ents]
        blob = TextBlob(rawtext)
        blob_sentiment, blob_subjectivity = blob.sentiment.polarity, blob.sentiment.subjectivity
        # allData = ['Token:{},Tag:{},POS:{},Dependency:{},Lemma:{},Shape:{},Alpha:{},IsStopword:{}'.format(token.text,token.tag_,token.pos_,token.dep_,token.lemma_,token.shape_,token.is_alpha,token.is_stop) for token in docx ]
        allData = [(
            '"Token":"{}","Tag":"{}","POS":"{}","Dependency":"{}","Lemma":"{}","Shape":"{}","Alpha":"{}","IsStopword":"{}"'
            .format(token.text, token.tag_, token.pos_, token.dep_,
                    token.lemma_, token.shape_, token.is_alpha, token.is_stop))
                   for token in docx]

        result_json = json.dumps(allData, sort_keys=False, indent=2)

        end = time.time()
        final_time = end - start
    return render_template('index.html',
                           ctext=rawtext,
                           custom_tokens=phrases,
                           custom_postagging=bold,
                           custom_namedentities=important,
                           custom_wordinfo=text,
                           blob_sentiment=bold,
                           blob_subjectivity=blob_subjectivity,
                           final_time=final_time,
                           result_json=result_json)
Exemplo n.º 28
0
def show_page(slideshow, zone, page_num):
    # if table of contents is not empty, add it
    if slideshow.contents:
        toc = html.SELECT(name="toc")
        toc.bind('change', lambda ev: show_page(slideshow, zone, 
            int(ev.target.options[ev.target.selectedIndex].value)))
        for content in slideshow.contents:
            toc <= html.OPTION(content[0], value=content[1],
                selected=page_num>=content[1])

    slideshow.page_num = int(page_num)
    
    # store page num in a cookie
    document.cookie = "page={}".format(page_num)

    zone.clear()
    
    body = html.DIV()
    body.html = markdown.mark(slideshow.pages[page_num])[0]

    wh = window.innerHeight
    fontSize = int(18 * window.innerHeight / 800)
    body.style.fontSize = "{}px".format(fontSize)
    
    if slideshow.contents:
        body = html.DIV(toc + body)

    footer = html.DIV(Id="footer")
    footer.style.fontSize = "{}px".format(fontSize)
    if slideshow.title:
        footer <= html.DIV(slideshow.title,style=dict(display='inline'))
    if slideshow.show_page_num:
        footer <= html.SPAN(' (%s/%s)' %(page_num+1, len(slideshow.pages)),
            style=dict(display='inline'))
    timeline = html.DIV(Id='timeline')
    timeline.style.height = "{}px".format(int(fontSize/2))
    tl_pos = html.DIV(Id='tl_pos')
    timeline <= tl_pos
    timeline.bind('click', lambda ev:move_to(ev, slideshow, zone))
    tl_pos.bind('click', click_on_tl_pos)

    zone <= body + footer + timeline

    wh = window.innerHeight
    tl_pos.style.left = '%spx' %(timeline.width*page_num/len(slideshow.pages))
    document["cours"].style.minHeight = "{}px".format(int(wh * 0.9))
    
    for elt in zone.get(selector='.python'):
        src = elt.text.strip()
        width = max(len(line) for line in src.split('\n'))
        width = max(width, 30)
        # replace element content by highlighted code
        elt.html = highlight.highlight(src).html
        elt.style.width = '%sem' %int(0.7*width)
        elt.bind('click', run_code)

    for elt in zone.get(selector='.python-console'):
        src = elt.text.strip()
        lines = src.split('\n')
        result = ''
        py = ''
        py_starts = []
        for line in lines:
            if line.startswith('>>>') or line.startswith('...'):
                py += line[4:]+'\n'
                py_starts.append('<span class="python-prompt">{}</span>'.format(line[:3]))
            else:
                if py:
                    colored = highlight.highlight(py).html
                    colored_lines = colored.split('\n')
                    if result:
                        result += '\n'
                    result += '\n'.join(start+' '+line
                        for (start, line) in zip(py_starts, colored_lines))
                    py = ''
                    py_starts = []
                else:
                    line = escape(line)
                result += '\n' + line
        if py:
            colored = highlight.highlight(py).html
            colored_lines = colored.split('\n')
            if result:
                result += '\n'
            result += '\n'.join(start+' '+line
                for (start, line) in zip(py_starts, colored_lines))
            py = ''
            py_starts = []

        elt.html = result
Exemplo n.º 29
0
if re.match(r':?/?([.a-zA-Z0-9_-]+/)+', fileName):
    directory = fileName[:fileName.rfind('/')+1]

numSentences = int(input('Number of sentences in summary: '))
numKey = int(input('Number of key phrases: '))
text = PDF2Text(fileName)
print('---text loaded---')
clean(text)
print('---cleaned---')
summarize('cleantext.txt', numSentences, directory)
print('---summarized---')
keyphrases = get_key_phrases(numKey, directory)
print('---key phrases found---')
make_pdf(keyphrases, directory)
print('---pdf made---')
highlight(keyphrases, directory)
print('---pdf highlighted---')
if platform.system() == 'Windows':
    subprocess.run(['del', 'cur_img.png'], shell = True)
    subprocess.run(['del', 'cur_txt.txt'], shell = True)
    subprocess.run(['del', 'cur_pdf.pdf'], shell = True)
    subprocess.run(['del', 'cleantext.txt'], shell = True)
    subprocess.run(['del', 'searchable.pdf'], shell = True)
else:
    subprocess.run(['rm', 'cur_img.png'])
    subprocess.run(['rm', 'cur_txt.txt'])
    subprocess.run(['rm', 'cur_pdf.pdf'])
    subprocess.run(['rm', 'cleantext.txt'])
    subprocess.run(['rm', 'searchable.pdf'])
print('done')
Exemplo n.º 30
0
def enter_url():
    if request.method == 'GET':
        return render_template('enter_url.html')
    else:
        highlight(request.form['url'], d)
        return render_template('highlighted_article.html')