Code Monkey home page Code Monkey logo

smmryapi's Introduction

SMMRY API Wrapper for Python

Getting Started

To get started you'll need to sign up for the app and register for a partner account. In "free mode", you can submit up to 100 requests in 24 hours. Once you obtain your API key, export it as an environment variable in your shell. (Aternatively, assign your key to a new variable once you're in python.)

In shell:

$ pip install -r requirements.txt

$ export SMMRY_API_KEY='YOUR API KEY HERE'

In Python:

import os

SMMRY_API_KEY = os.environ.get('SMMRY_API_KEY')

Altnernatively...

SMMRY_API_KEY = 'YOUR API KEY HERE'

Once your have your key, import the module and create an instance of the Smmry object.

from smmryapi import SmmryAPI

smmry = SmmryAPI(SMMRY_API_KEY)

Requesting Summaries

To request the summary for an article pass an article's URL to the .summarize() method. A URL is the only required parameter, and by default, the method will return a seven-sentence summary. I'll use this this BBC article as an example with sm_length=3 to request a three-sentence summary.

(The maximum sentences retrieved is 40.)

url = 'http://www.bbc.com/news/business-43298897'

s = smmry.summarize(url,sm_length=3)

The method returns a Summary object with a varying set of attributes (depending on your parameters).

Accessing summaries...

Article summaries will be store in the sm_api_content attribute.

s.sm_api_content
'Too many Lego bricks is a problem many parents will sympathise with, but now the toy firm itself has admitted it has made too many. 915,103,765 - the number of ways to combine six two-by-four Lego bricks of the same colour. 3,700 - the number of different types of Lego bricks. In September, Lego said its half-year results had suffered because it had stretched itself too thin by diversifying into products that were not toys, such as the Lego movies. Lego chairman Jorgen Knudstorp said at the time that adding complexity to the company had made it harder for the toymaker to grow further.'

Accessing keywords...

If you pass an integet to sm_keyword_count it will return the requested number of keywords for that article. Note that the sm_api_keyword_array will only be available if a value for sm_keyword_count is selected.

s = smmry.summarize(url,sm_length=3,sm_keyword_count=12)

s.sm_api_keyword_array

Other attributes...

To check out other attributes view the official documentation or or run s.__dict__.keys().

s = smmry.summarize(url,sm_length=5,sm_keyword_count=3)
    
attributes = (
    s.sm_domain,               # The domain name of the URL
    s.sm_api_title,            # The article's titled 
    s.sm_url,                  # URL of the article 
    s.sm_api_content_reduced,  # Percent by which reduced
    s.sm_length,               # Number of sentences 
    s.sm_requests_remaining,   # Number of queries left
    s.sm_api_keyword_array     # Keywords
)

result = """

SMMRY reduced %s article "%s" from url
[%s] by %s to %s sentences.

You have %s requests remaining today.

Top keywords are: %s.'
"""

print(result % attributes)
SMMRY reduced bbc.com article "Lego admits it made too many bricks" from url
[http://www.bbc.com/news/business-43298897] by 80% to 5 sentences.

You have 5 requests remaining today.

Top keywords are: ['Lego', 'sales', 'year'].'

smmryapi's People

Contributors

dsynkov avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.