How to use the html.unescape function in html

To help you get started, we’ve selected a few html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astrocatalogs / supernovae / supernova.py View on Github external
bibcodeauthor = ''
                        try:
                            response = urllib.request.urlopen(adsquery)
                            html = response.read().decode('utf-8')
                            hsplit = html.split("\n")
                            if len(hsplit) > 5:
                                bibcodeauthor = hsplit[5]
                        except:
                            pass

                        if not bibcodeauthor:
                            warnings.warn(
                                "Bibcode didn't return authors, not converting"
                                "this bibcode.")

                        self.catalog.bibauthor_dict[bibcode] = unescape(
                            bibcodeauthor).strip()

            for source in self[self._KEYS.SOURCES]:
                if (SOURCE.BIBCODE in source and
                        source[SOURCE.BIBCODE] in self.catalog.bibauthor_dict
                        and
                        self.catalog.bibauthor_dict[source[SOURCE.BIBCODE]]):
                    source[SOURCE.REFERENCE] = self.catalog.bibauthor_dict[
                        source[SOURCE.BIBCODE]]
                if (SOURCE.NAME not in source and SOURCE.BIBCODE in source and
                        source[SOURCE.BIBCODE]):
                    source[SOURCE.NAME] = source[SOURCE.BIBCODE]

        if self._KEYS.REDSHIFT in self:
            self[self._KEYS.REDSHIFT] = list(
                sorted(
github sx4-discord-bot / Sx4-Python / Sx4 / cogs / fun.py View on Github external
request = requests.get("http://localhost:8080/translate/{}?{}".format(language, urllib.parse.urlencode({"q": text.lower()})), timeout=3)
        try:
            await ctx.send(request.json()["message"].replace("'", "`") + " :no_entry:")
        except:
            input_text = request.json()["from"]["language"]["iso"]
            if "-" in input_text:
                input_text = input_text.split("-")[0]
            if input_text == "iw":
                input_text = "Hebrew"
            elif len(input_text) == 2:
                input_text = languages.get(part1=input_text).name
            elif len(input_text) == 3:
                input_text = languages.get(part3=input_text).name
            s=discord.Embed(colour=0x4285f4)
            s.set_author(name="Google Translate", icon_url="https://upload.wikimedia.org/wikipedia/commons/d/db/Google_Translate_Icon.png")
            s.add_field(name="Input Text ({})".format(input_text), value=html.unescape(request.json()["from"]["text"]["value"]) if request.json()["from"]["text"]["value"] else text, inline=False)
            s.add_field(name="Output Text ({})".format(language.title()), value=request.json()["text"])
            await ctx.send(embed=s)
github ExtensiveAutomation / extensiveautomation-server / app-plugins / client / hp-alm-qc / RestAPI.py View on Github external
data.append( "%s" % stepName )
        data.append( "%s" % self.__gethtml(stepDescription) )
        data.append( "%s" % self.__gethtml(stepExpected) )
        
        data.append( "" ) 
        data.append( "" )
        
        r = requests.post("%s/rest/domains/%s/projects/%s/design-steps" % (self.WsUrl, self.WsDomain, self.WsProject), 
                        cookies={ 'LWSSO_COOKIE_KEY': self.WsLwssoCookie, 'QCSession': self.WsQcSession } ,
                        headers = {'Content-Type': 'application/xml;charset=utf-8'},
                        data="\n".join(data).encode("utf8"),
                        proxies=self.WsProxies, verify=self.WsCheckSsl)
        if r.status_code != 201:
            errTitle = r.text.split("<title>")[1].split("</title>", 1)[0]
            errTitle = html.unescape(errTitle)
            raise Exception( "Unable to create step: %s - %s" % (r.status_code, errTitle) )
        return True
github tjcsl / cslbot / cslbot / helpers / textutils.py View on Github external
def gen_translate(msg, fromlang=None, tolang='en'):
    key = config.get_config()['api']['googleapikey']
    if not key:
        raise Exception('Invalid translate api key')
    if tolang not in get_languages(key):
        return "Invalid target language."
    params = {'key': key, 'q': msg, 'target': tolang}
    if fromlang is not None:
        if fromlang not in get_languages(key):
            return "Invalid source language."
        params.update({'source': fromlang})
    data = get('https://www.googleapis.com/language/translate/v2', params=params).json()
    return unescape(data['data']['translations'][0]['translatedText'])
github Shivanshu-Gupta / hierarchical-attention-network / preprocess.py View on Github external
def load_data(datafile):
    import html
    samples = [json.loads(line) for line in open(datafile).readlines()]
    data = {}
    data['review'] = [html.unescape(sample['reviewText']) for sample in samples]
    data['summary'] = [html.unescape(sample['summary']) for sample in samples]
    data['rating'] = np.array([sample['overall'] for sample in samples])

    classes = np.array([0, 1, 2])

    def target(rating):
        if rating &lt;= 2:
            return classes[0]
        elif rating == 3:
            return classes[1]
        else:
            return classes[2]
    data['target'] = np.array([target(rating) for rating in data['rating']])

    return data
github rss2email / rss2email / rss2email / feed.py View on Github external
'feed-url': self.url,
            'feed-title': '',
            'author': '',
            'publisher': '',
            }
        feed = parsed.feed
        data['feed-title'] = feed.get('title', '')
        for x in [entry, feed]:
            if 'name' in x.get('author_detail', []):
                if x.author_detail.name:
                    data['author'] = x.author_detail.name
                    break
        if 'name' in feed.get('publisher_detail', []):
            data['publisher'] = feed.publisher_detail.name
        name = self.name_format.format(**data)
        return _html.unescape(name)
github bennuttall / meme-overflow / memeoverflow / memeoverflow.py View on Github external
def generate_meme_and_tweet(self, question):
        """
        For the given question, if it's not known:
        - generate meme
        - tweet it
        - add to database
        Return True on success, False on fail or question was known
        """
        question_title = html.unescape(question['title'])
        question_url = self.get_question_url(question['link'])
        question_id = question['question_id']
        tags = tags_to_hashtags(question['tags'])
        status = f'{question_title} {question_url} {tags}'
        if len(status) > 240:
            status = f'{question_title} {question_url}'
            logger.info('Tweet too long - removing tags')
        img_url, meme = self.make_meme(question_title)
        try:
            self.tweet(status, img_url)
            logger.info(f'Tweeted: {question_title} [{meme}]')
        except TwythonError:
            return False
        self.db.insert_question(question_id)
        return True
github HuberTRoy / Seen / seen / item.py View on Github external
def __init__(self, spider, response, isJson=False):
        self.html = response.text
        self.result = {}
        self.spider = spider
        self.response = response
        if isJson:
            try:
                self.result['json'] = json.loads(self.html)
            except:
                logger.error("The JSON contents returned by URL ({}) loaded failure, please check again.".format(
                    response.url), exc_info=True)
        else:
            self.html = unescape(self.html)

            for name, selector in self.selector.items():
                contents = selector.get_select(self.html)
                if contents is None:
                    logger.error('selector "{}:{}" was error, please check again.'.format(
                        name, selector), exc_info=True)
                    continue

                self.result[name] = contents
github Exaphis / HackQ-Trivia / hackq_trivia / searcher.py View on Github external
def html_to_visible_text(html):
        soup = bs4.BeautifulSoup(html, features='html.parser')
        for s in soup(['style', 'script', '[document]', 'head', 'title']):
            s.extract()

        return unidecode(unescape(soup.get_text())).lower()
github kashav / nba.js / stringify.py View on Github external
def single(game):
    team_1, score_1 = game['visitor']['name'].ljust(14), game['visitor']['score'].rjust(3)
    team_2, score_2 = game['home']['name'].rjust(14), game['home']['score'].ljust(3)
    output = '{} {} : {} {} [{}]'.format(team_1, score_1, score_2, team_2, game['status'])
    # team_1, score_1 = game['visitor']['name'], game['visitor']['score']
    # team_2, score_2 = game['home']['name'], game['home']['score']
    # output = '{} {} : {} {} [{}]'.format(team_1, score_1, score_2, team_2, game['status'])
    return html.unescape(output)