Git Product home page Git Product logo

newscatcher's Introduction

Newscatcher

Programmatically collect normalized news from (almost) any website. By newscatcherapi.com.

Demo

Motivation

While working on newscatcherapi -- JSON API to query the news articles, I came up with an idea to make a simple Python package that would allow to easily grab the live news data.

When I used to be a junior data scientist working on my own side projects, it was difficult for me to operate with external data sources. I knew Python quite well, but in most cases it was not enough to build proper data pipelines that required gathering data on my own.

Even though I do not recommend to use this package for any production systems, I believe that it should be enough to test your assumptions and build some MVPs.

Installation

pip install newscatcher

Tech/framework used

The package itself is nothing more than a SQLite database with RSS feed endpoints for each website and some basic wrapper of feedparser.

Code Example/Documentation

Let's review all possible usage of the package.

In its core, it has a class called Newscatcher. This class is all you need in order to get latest news.

After installing your package, import the class:

from newscatcher import Newscatcher

Now you just need to put a url of a desired news source as an input into our class. Please take the base form url of a website (without www.,neither https://, nor / at the end of url).

For example: “nytimes”.com, “news.ycombinator.com” or “theverge.com”.

news_source = Newscatcher('blackfaldslife.com')

If you have done it right and the source that you chose is presented in our database, you will get a variable with 3 components and 1 method:

  • news_source.website -- the same string that you entered inside the class.
  • news_source.news -- a list of a feedparser dictionary with latest news presented on the website.
  • news_source.headlines -- a list with latest headlines presented on the website.
  • news_source.print_headlines() -- print headlines of all latest articles.

Each element of news list is a json object with all relevant and available information regarding an article. If you want to know more about the attributes that you can extract from this json, go check the official documentation of feedparser following this link: feedparser_attributes. You can find everything that begins with entries[i]. But be aware that not all the attributes are provided by the news website.

If for some reason you do not like classes, you can always import 2 main methods and use them separately.

from newscatcher import get_news news = get_news('wired.co.uk')

or

from newscatcher import get_headlines news = get_headlines('wired.co.uk')

Licence

MIT

newscatcher's People

Contributors

kotartemiy avatar dwardu89 avatar

Watchers

James Cloos 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.