Giter Club home page Giter Club logo

news_content_collect_store's Introduction

News_content_collect_store

This repo contains code to crawl for articles from the BBC, cleanse them, store them in MongoDB, and then make it available to search via an API.

The purpose is to fulfill a coding challenge. Some of the used frameworks are requests, Beautifulsoup.

Re-usable functions

The file contains an API and some code applying it. Several functions provide some abstraction and allows for re-use as below:

  1. give_links(url, parent): Takes a url, and its parent address and returns a list of absolute addresses of web links orginitating from it.

  2. is_news_article(link):
    Takes a web link address and tests whether the link contains a news article in BBC. Returns 1 if True, 0 otherwise.

  3. follow_links(origin_link, test_func, n_other_links_to_follow = 1): Takes a link and starts following all links it contained searching for a pattern specificed by boolean function test_func. It adds them to matching_urls list. Other links that doesn't match the specified pattern are added to another list (other_urls).

The function will then crawl a number of them specified by another function parameter (n_other_links_to_follow) which is set to 1 by default. Generally, increasing this number will consume more time but will yield more articles too.

Args: -origin link: a string of the URL address () -test_func: a callable that takes a string of a URL link and outputs 1 if the link matches a specified pattern, 0 otherwise. -n_other_links_to_follow : number of links to follow from the other_urls list () Returns: -Two python lists containing matching_urls and other_urls

  1. retrieve_documents(database, collection): Takes a MongoDB database and collection name, and returns all documents in collection to a pandas dataframe. You have to have an established connection.

  2. search(search_text, database, collection): Takes a a string containing keywords and outputs all relevant articles to any of them.

Args: -search_text: a string of keywords () -database: MongoDB database name (<pymongo.database.Database>) -collection: string with the name of MongoDB collection () Returns: -A pandas dataframe containing the MongoDB contents of the returned news articles

I have created a hosted MongodDB atlas database and connected to it in the code using my credentials (provided in the code)

Reference

Please refer to https://github.com/Isentia/Coding-Challenge who posted this coding challenge.

Questions

Please email me at [email protected]

news_content_collect_store's People

Contributors

alyrazik 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.