Skip to content

python-dev-og/climate-change-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Badge npm Badge JavaScript Badge Cheerio Badge Express Badge Axios Badge

Climate Change News API

Description

This Node.js application serves as a simple API to fetch climate change news articles from various online newspapers. The application uses express for setting up the server, axios for HTTP requests, and cheerio for parsing HTML content. The API scrapes specified news websites for articles containing the keyword "climate" and presents these articles in a JSON format.

Features

  • Fetches and displays a list of climate change related news articles.
  • Allows filtering news articles by specific newspaper sources.
  • Dynamically constructs article URLs from relative paths using base URLs.

Installation

Before installation, ensure you have Node.js and npm installed on your system.

  1. Clone the repository:
    git clone [repository-url]
  2. Navigate to the project directory:
    cd [project-directory]
  3. Install dependencies:
    npm install

Commands to write the program from scratch on your local machine

node -v
npm init 
npm i cheerio
npm i express
npm i axios
npm i nodemon
npm run start

Usage

Start the server with the following command:

npm run start

The server runs on localhost with the default port 8000 (configurable through environment variables).

Endpoints

  1. Homepage (/):

    • Returns a welcome message.
    • Method: GET
  2. All News (/news):

    • Returns a JSON object with an array of all collected climate change news articles.
    • Method: GET
  3. News by Newspaper (/news/:newspaperId):

    • Replace :newspaperId with the desired newspaper's name to get articles specifically from that source.
    • Method: GET

Supported Newspapers

  • CityAM
  • The Times
  • The Guardian
  • The Telegraph
  • New York Times
  • Los Angeles Times
  • Sydney Morning Herald
  • BBC
  • Evening Standard
  • The Sun
  • Daily Mail
  • New York Post
  • NASA
  • CNN
  • CBS News
  • USA Today
  • ABC News

Configuration

The newspapers array in index.js contains the configuration for each newspaper source, including the name, base URL, and specific climate change section URL.

Known Issues

  • The link for 'UN News' is currently commented out due to issues causing API crashes.

License

This project is licensed under the MIT License.

Disclaimer

This API is for educational purposes only. The scraping functionality might be against the terms of service of the news websites. Always ensure compliance with legal guidelines and website terms when scraping data.

Final Look

newspage.png

newspaperId.png

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published