# NDTV News API

This API will scrap the news content present in the NDTV website will provide the data in a JSON format.

URL : https://ndtvnews-api.herokuapp.com

Available Endpoints

Below are the endpoints available in this API. | S. No | Categories | Endpoints | | ----- | ----------- | ----------- | | 1 | General News| /general | | 2 | Sports News | /sports | | 3 | City News | /cities |

Field Names

| S. No | Field Name | Content | | ----- | ----------- | ---------------------- | | 1 | category | News Classification | | 2 | headline | News Headline | | 3 | description | News Short Description | | 4 | url | Actual News Url | | 5 | image_url | News Image | | 6 | posted_date | Posted Date |

Usage

Please find the instructions for using the respective endpoints.

For https://ndtvnews-api.herokuapp.com/general :-

This endpoint will give you the news for the below mentioned categories.

>

>

    >
  1. latest //latest news available in NDTV site for all categories
  2. >
  3. india //Indian National News
  4. >
  5. world
  6. >
  7. science
  8. >
  9. business
  10. >
  11. entertainment
  12. >
  13. offbeat
  14. >
>


This endpoint has the below two keys which you can use to get the more specific News with the content you wish to get.

Key | Name |Example ---------|----------|--------- category | news category you wish to get | https://ndtvnews-api.herokuapp.com/general?category=values(latest,india,world) field | field content | https://ndtvnews-api.herokuapp.com/general?field=values(headline,description,url)

GET REQUEST :-


``` https://ndtvnews-api.herokuapp.com/general?category=values(latest)&field=values(headline,description,url) ```

OUTPUT :-


```JSON { "news": [ { "category": "latest", "total_results": 2, "articles": [ { "headline": "25,000 Tonnes Of Oxygen Delivered Across India So Far: Railways", "description": "The railways 'Oxygen Express' trains have crossed the milestone of delivering 25,000 tonnes of liquid medical oxygen across 39 cities in 15 states/UTs amid the COVID-19 outbreak, the national transporter said on Saturday.", "url": "https://www.ndtv.com/india-news/25-000-tonnes-of-oxygen-delivered-across-india-so-far-railways-2457156", }, { "headline": "Monsoon Arrives In Maharashtra; Conditions Favourable For Advancement: Weather Office", "description": "The southwest monsoon arrived in Maharashtra on Saturday, bringing showers in some coastal parts of the state, an India Meteorological Department (IMD) official said.", "url": "https://www.ndtv.com/india-news/monsoon-arrives-in-maharashtra-conditions-favourable-for-advancement-weather-office-2457092", } ] }, { "category": "india", "total_results": 1, "articles": [ { "headline": "Haryana Farmers March On Police Station In Showdown Over Spat With MLA", "description": "Hundreds of farmers marched on the police station in Haryana's Tohana Saturday to court arrest in protest of the arrest of three of their colleagues, and raids on their camps and homes, after a spat with local MLA Devendra Babli of the JJP", "url": "https://www.ndtv.com/india-news/farmers-protest-tohana-haryana-farmers-march-on-police-station-in-showdown-over-spat-with-mla-2457164", } ] }, { "category": "world", "total_results": 2, "articles": [ { "headline": "Turkish Drone Strike Kills 3 Civilians In Iraq Refugee Camp", "description": "Three civilians were killed Saturday in a Turkish drone attack on a refugee camp in northern Iraq in an area Turkish President recently threatened to \"clean up\", a Kurdish lawmaker said.", "url": "https://www.ndtv.com/world-news/turkish-drone-strike-kills-3-civilians-in-iraq-refugee-camp-2457161", }, { "headline": "Global Terror Funding Watchdog Retains Pak On \"Enhanced Follow-Up\" List", "description": "The Asia Pacific Group on Money Laundering has retained Pakistan on \"enhanced follow-up\" status for outstanding requirements.", "url": "https://www.ndtv.com/world-news/global-terror-funding-watchdog-fatf-retains-pakistan-on-enhanced-follow-up-list-2457134", } ] } ] } ```

Hence, it will give you a dictionary with a key called news and the value containing a list of dictionaries (this dictionary will hold the requested news category, total_results and the news data list) for the requested categories.

If you are not specifying any keys and just simply hit the endpoint, it will give you the news from latest category with all the available fields (category, headline, description, url, image_url, posted_date).


For https://ndtvnews-api.herokuapp.com/cities :-

This will give you the news related to the below mentioned cities.

>

>

    >
  1. agra
  2. >
  3. ahmedabad
  4. >
  5. allahabad
  6. >
  7. amritsar
  8. >
  9. aurangabad
  10. >
  11. bangalore
  12. >
  13. bhopal
  14. >
  15. bhubaneshwar
  16. >
  17. chandigarh
  18. >
  19. chennai
  20. >
  21. delhi
  22. >
  23. ghaziabad
  24. >
  25. goa
  26. >
  27. gurgaon
  28. >
  29. guwahati
  30. >
  31. hyderabad
  32. >
  33. jaipur
  34. >
  35. jammu
  36. >
  37. kanpur
  38. >
  39. kolkata
  40. >
  41. lucknow
  42. >
  43. ludhiana
  44. >
  45. meerut
  46. >
  47. mumbai
  48. >
  49. muzaffarnagar
  50. >
  51. muzaffarpur
  52. >
  53. nagpur
  54. >
  55. noida
  56. >
  57. others //will contain the news for other cities which are not mentioned here
  58. >
  59. patna
  60. >
  61. pune
  62. >
  63. srinagar
  64. >
  65. surat
  66. >
  67. thiruvananthapuram
  68. >
>


This endpoint has the below two keys which you can use to get the more specific News with the content you wish to get.

Key | Name |Example ---------|----------|--------- city | name of the city you wish to get the news | https://ndtvnews-api.herokuapp.com/cities?city=values(chennai,mumbai,delhi) field | field content | https://ndtvnews-api.herokuapp.com/cities?field=values(headline,image_url,posted_date)

GET REQUEST :-


``` https://ndtvnews-api.herokuapp.com/cities?city=values(chennai,mumbai,delhi)&field=values(headline,image_url,posted_date) ```

OUTPUT :-


```JSON { "news": [ { "category": "chennai", "total_results": 200, "articles": [ { "headline": "Lioness Died Of Suspected SARS-CoV2, 8 Lions Infected At Chennai Zoo", "image_url": "https://c.ndtvimg.com/2018-10/rmmns24g_lioness_120x90_21_October_18.jpg", "posted_date": "2021-06-04" } ] }, { "category": "mumbai", "total_results": 200, "articles": [ { "headline": "Air Force Bus Meets With Accident In Mumbai, 5 Injured", "image_url": "https://i.ndtvimg.com/i/2017-08/hospital-generic-file_240x180_51502360464.jpg", "posted_date": "2021-03-16" }, { "headline": " Actor Pearl Puri Arrested For Allegedly Raping Minor: Report", "image_url": "https://c.ndtvimg.com/2021-06/igfmjj2s_pearl-puri-instagram_120x90_05_June_21.jpg", "posted_date": "2021-06-05" } ] }, { "category": "delhi", "total_results": 200, "articles": [ { "headline": "Delhi Reports 414 Covid Cases, Lowest In Over 2 Months, 60 Deaths", "image_url": "https://c.ndtvimg.com/2020-11/jj4ilhc_coronavirus-delhi-november-2020-pti-240_240x180_23_November_20.jpg", "posted_date": "2021-06-05" }, { "headline": "2nd Covid Wave Peaked At 28,000 Cases A Day, 3rd Wave May Reach 37,000: Arvind Kejriwal", "image_url": "https://c.ndtvimg.com/2021-05/plmda16_coronavirus-india-generic-pti_120x90_07_May_21.jpg", "posted_date": "2021-06-05" } ] } ] } ```

Hence, it will give you a dictionary with a key called news and the value containing a list of dictionaries (this dictionary will hold the requested city, total_results and the news data list) for the requested cities.

If you are not specifying any keys and just simply hit the endpoint, it will give you the top news from all the cities across India with all the available fields (category, headline, description, url, image_url, posted_date).


For https://ndtvnews-api.herokuapp.com/sports :-

This will give you the news related to the below mentioned sports.

>

>

    >
  1. cricket
  2. >
  3. football
  4. >
  5. tennis
  6. >
  7. formula-1
  8. >
  9. hockey
  10. >
  11. golf
  12. >
  13. badminton
  14. >
  15. chess
  16. >
  17. kabaddi
  18. >
  19. wrestling
  20. >
  21. nba
  22. >
  23. boxing
  24. >
>

>

This endpoint has the below two keys which you can use to get the more specific News with the content you wish to get.

Key | Name |Example ---------|----------|--------- sport | name of the sport you wish to get the news| https://ndtvnews-api.herokuapp.com/sports?sport=values(cricket,football) field | field content | https://ndtvnews-api.herokuapp.com/sports?field=values(headline,description,url)

GET REQUEST :-


``` https://ndtvnews-api.herokuapp.com/sports?sport=values(cricket,football)&field=values(headline,description,url) ```

OUTPUT :-


```JSON { "news": [ { "category": "cricket", "total_results": 18, "articles": [ { "headline": "Ankeet Chavan Requests BCCI Through MCA To Issue Ban Revocation Letter", "description": "Left-arm spinner Ankeet Chavan has requested the BCCI to issue his ban revocation letter which would allow him to return to competitive cricket.", "url": "https://sports.ndtv.com//cricket/ankeet-chavan-requests-bcci-through-mca-to-issue-ban-revocation-letter-2457241" }, { "headline": "Rashid Khan Sums Up Virat Kohli In \"One Word\", Hails MS Dhoni In Special Tribute", "description": "Entertaining fans via a Q&A session on Instagram, Rashid Khan glorified Virat Kohli, and had special praise for former India captain MS Dhoni.", "url": "https://sports.ndtv.com//cricket/rashid-khan-sums-up-virat-kohli-in-one-word-hails-ms-dhoni-in-special-tribute-2456442" } ] }, { "category": "football", "total_results": 18, "articles": [ { "headline": "FIFA World Cup Qualifiers: India Gears Up For Bangladesh Game After Qatar Loss", "description": "After losing 1-0 to Qatar, the Indian football team will take on Bangladesh in the FIFA WC Qualifiers match on June 7.", "url": "https://sports.ndtv.com//football/fifa-world-cup-qualifiers-india-gears-up-for-bangladesh-game-after-qatar-loss-2457028" }, { "headline": "Spain And Portugal In Lukewarm Stalemate Ahead Of European Championships", "description": "Spain and Portugal both lacked firepower as they drew 0-0 in a friendly warm up for the European Championships at the Metropolitano in Madrid.", "url": "https://sports.ndtv.com//football/spain-and-portugal-in-lukewarm-stalemate-ahead-of-euros-2020-2456805" }, { "headline": "World Cup Qualifiers: Retaken Neymar Penalty Helps Brazil Maintain Perfect Start", "description": "Richarlison had given Brazil the lead on 64 minutes and Neymar sealed the win deep into injury time, but only after another VAR farce.", "url": "https://sports.ndtv.com//football/world-cup-qualifiers-retaken-neymar-penalty-helps-brazil-maintain-perfect-start-2456792" } ] } ] } ```

Hence, it will give you a dictionary with a key called news and the value containing a list of dictionaries (this dictionary will hold the requested sport, total_results and the news data list) for the requested sports.

If you are not specifying any keys and just simply hit the endpoint, it will give you the top cricket news with all the available fields (category, headline, description, url, image_url, posted_date).


Installation and Setup

All dependencies are listed in _requirements.txt_ file. 1. To install dependencies, run - ```bash $ pip install -r requirements.txt ``` 2. Database - It will take considerable amount of time to scrap all the data present in NDTV website in live time for each request. So, HEROKU POSTGRES DB (flask sqlite can also be used) has been used to store the scrapped data. The database will be feed with latest news present in the NDTV website for every 10 minutes which inturn will feed a pandas dataframe. Once a request is received, it will query the dataframe for the requested data and will provide the JSON response. 3. Start the api server - ```bash $ python app.py ```

Contributing

I am a newbie and this is my First Project in Flask API and also in Github. So, advices, corrections, suggestions and pull requests are happily welcome and let us engage in discussions

For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

©Nishanth