def summarization(url):
    from aylienapiclient import textapi
    summarizedtext = ""
    client = textapi.Client("357c1a5a", "458f8b52cec9fdbfd260a52d728c9d80")

    summary = client.Summarize({'url': url, 'sentences_number': 3})
    for sentence in summary['sentences']:
        summarizedtext = summarizedtext + " " + sentence
    return (summarizedtext)
Example #2
0
def get_articles(headline):
    client = textapi.Client(app.config['AYLIEN_APP_ID'], app.config['AYLIEN_KEY'])

    # load json
    bing = app.config['BING_SEARCH']

    headers = {
        # Request headers
        'Ocp-Apim-Subscription-Key': bing,
    }

    params = urllib.parse.urlencode({
        # Request parameters
        'q': headline,
        'count': '15',
        'offset': '0',
        'mkt': 'en-us',
        'safeSearch': 'Moderate',
    })

    try:
        conn = http.client.HTTPSConnection('api.cognitive.microsoft.com')
        conn.request("GET", "/bing/v5.0/news/search?%s" % params, "{body}", headers)
        print(conn)
        print(4)
        print(5)
        response = conn.getresponse()
        data = response.read()
        conn.close()
    except Exception as e:
        print("[Errno {0}] {1}".format(e.errno, e.strerror))

    # query the json, create article objects   
    decoded_data = json.loads(data.decode())

    article_list = []

    for i in decoded_data['value']:

        title = i['name']   
        url = i['url']
        source = i['provider'][0]['name']
        date = i['datePublished']
        summary_data = client.Summarize({'url': url, 'sentences_number': 1}) # list
        summary = summary_data['sentences']
        hashtags_data = client.Hashtags({"url": url}) # is a list
        hashtags = hashtags_data['hashtags']
        sentiment = client.Sentiment({'url': url})
        polarity = sentiment['polarity']
        polarity_confidence = sentiment['polarity_confidence']
        subjectivity = sentiment['subjectivity']
        subjectivity_confidence = sentiment['subjectivity_confidence']
        article_list.append(Article(title, url, source, date, summary, hashtags, polarity, polarity_confidence, subjectivity, subjectivity_confidence))
 
    return article_list
Example #3
0
def summarization(url):
    """
    Uses Aylien's Text Summarization API to summarize the text content of the
    page at the given URL.
    Returns the summarized text as a string.
    """
    from aylienapiclient import textapi
    client = textapi.Client(AYLIEN_APP_ID, AYLIEN_APP_KEY)

    summary = client.Summarize({'url': url, 'sentences_number': 3})
    if len(summary['sentences']) == 0:
        return ""
    else:
        return " ".join(sentence for sentence in summary['sentences'])
Example #4
0
def summarization(url):
    """
    Uses Aylien's Text Summarization API to summarize the text content of the
    page at the given URL.
    Returns the summarized text as a string.
    """
    from aylienapiclient import textapi
    summarizedtext = ""
    client = textapi.Client("357c1a5a", "458f8b52cec9fdbfd260a52d728c9d80")

    summary = client.Summarize({'url': url, 'sentences_number': 3})
    for sentence in summary['sentences']:
        summarizedtext = summarizedtext + " " + sentence;
    return summarizedtext
def summarization(url, api_logger):
    """
    Uses Aylien's Text Summarization API to summarize the text content of the
    page at the given URL.
    Returns the summarized text as a string.
    """
    api_logger.debug("SUMMARIZATION OF URL: {}".format(url))
    from aylienapiclient import textapi
    client = textapi.Client(AYLIEN_APP_ID, AYLIEN_APP_KEY)

    summary = client.Summarize({'url': url, 'sentences_number': 3})
    api_logger.debug(
        "RESULTS OF AyLien API -> No Sentences: {0} Raw Data: {1}".format(
            len(summary['sentences']), summary))
    if len(summary['sentences']) == 0:
        return ""
    else:
        return " ".join(sentence for sentence in summary['sentences'])