
// GetBBC.java
// Andrew Davison, ad@coe.psu.ac.th, July 2023

/* Get the headlines for BBC News. If a number
   is included then that article's URL is loaded into
   a browser.


  Usage:
    > compile GetBBC.java
    > run GetBBC [<story num>]
  e.g. 
    > run GetBBC
    > run GetBBC 5

  More info: https://newsapi.org/docs/endpoints/top-headlines
*/

import java.util.*;


public class GetBBC
{

  public static void main(String[] args)
  {
    int newsItem = -1;
    if (args.length > 1) {
      System.out.println("Usage: run GetBBC [<story num>]");
      return;
    }

    if (args.length == 1)
      newsItem = NewsUtils.getInt(args[0]);

    String request = "https://newsapi.org/v2/top-headlines?" +
                          "sources=bbc-news";
    News news = NewsUtils.getNews(request);
    if (news != null) {
      if (newsItem != -1)
        NewsUtils.showArticle(news, newsItem);
      else
        NewsUtils.listNews(news);
    }
  } /* main */

}  // end of GetBBC class

