Code Monkey home page Code Monkey logo

newsapi's Introduction

NewsAPI

API Documentation

BASE_URL = "https://saurav.tech/NewsAPI/"
top_headlines_api = "<BASE_URL>/top-headlines/category/<category>/<country_code>.json"
everything_api = "<BASE_URL>/everything/<source_id>.json"

Detailed documentation: Postman Documentation

Example

curl --request GET 'https://saurav.tech/NewsAPI/top-headlines/category/health/in.json'
{
  "status": "ok",
  "totalResults": 70,
  "articles": [
    {
      "source": {
        "id": null,
        "name": "Thestatesman.com"
      },
      "author": "SNS Web",
      "title": "‘Olympics in 2021 unrealistic unless COVID-19 vaccine found’ - The Statesman",
      "description": "Olympics is not the only sporting tournament to be pushed back because of the dreaded coronavirus pandemic and high-profile tournaments including the cash-rich Indian Premier League (IPL) have been affected.",
      "url": "https://www.thestatesman.com/sports/olympics-in-2021-unrealistic-unless-covid-19-vaccine-found1502879079-1502879079.html",
      "urlToImage": "https://www.thestatesman.com/wp-content/uploads/2020/03/Tokyo2020.jpg",
      "publishedAt": "2020-04-19T14:41:24Z",
      "content": "Holding the Tokyo Olympics any time before a vaccine is found will be “very unrealistic,” according to a leading global health expert. Professor Devi Sridhar said that the development of the vaccine will be key to when the Olympics can be held.\r\nSridhar, howe… [+1886 chars]"
    },
    ...
    ...
    ...
    {
      "source": {
        "id": null,
        "name": "Hindustantimes.com"
      },
      "author": "HT Correspondent",
      "title": "Covid-19: Staying at home and want to use AC? Here’s what you need to know - Hindustan Times",
      "description": "A recent study in China suggested that air conditioning aided the transmission of coronavirus infection between people in a restaurant.",
      "url": "https://www.hindustantimes.com/india-news/covid-19-staying-at-home-and-want-to-use-ac-here-s-what-you-need-to-know/story-ZToEjpKIT5DuT99xw4wz5M.html",
      "urlToImage": "https://www.hindustantimes.com/rf/image_size_960x540/HT/p2/2020/04/19/Pictures/virus-outbreak-india_5ceba5dc-81f4-11ea-aedf-4d2519fcedc3.jpg",
      "publishedAt": "2020-04-19T04:36:11Z",
      "content": "As coronavirus disease Covid-19 spreads rapidly, there is a barrage of information floating along with it on what should be used and what shouldn’t to check the spread of the disease.\r\nAmong such information is the use of air conditioners (ACs) - many on the … [+2178 chars]"
    }
  ]
}

Available sources for everything endpoint

Source id
BBC News bbc-news
CNN cnn
Fox News fox-news
Google News google-news

NOTE: Top headlines will include all sources which are available in newsapi.org

Available Countries

Country 2-letter ISO 3166-1 code
🇮🇳 India in
🇺🇸 USA us
🇦🇺 Australia au
🇷🇺 Russia ru
🇫🇷 France fr
🇬🇧 United Kingdom gb

Available categories

  • business
  • entertainment
  • general
  • health
  • science
  • sports
  • technology

Introduction

News API is an amazing source of information as it provides a single API that exposes breaking news headlines and older articles from over 3,000 news sources and blogs!

You can sign up here for a free developer plan which allows you to make 500 requests per day. One can easily exceed the limit

Solution

This project queries the newsapi at a regular interval and logs the reponse to a JSON file. This json file is then committed and pushed to github. Now one can get the latest news from this json instead of newsapi.

Pros

  • No API KEY needed
  • No limit on number of requests

Cons

  • Cannot query for news (Can be fixed by cloning this repo and customizing according to your needs)
  • Slightly delayed result (Can be reduced by reducing the query time interval to newsapi)

newsapi's People

Contributors

dataupdaterbot avatar dependabot[bot] avatar sauravkanchan avatar smarteam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

newsapi's Issues

how to get the top result

see taking all the data would increase the time of data loading. so, if it is possible likewise as the real news API provides you pageSize so how can we do that.

Entire content

Is it possible for you to provide entre content and note [+4994]

Also add inbuilt suppport for pagination.

Hi @SauravKanchan , first of all thank you for this wonderfull api:clap:.It would be amazing if you can add inbuilt support for pagination just likepageSize , page in the original newsapi.I know that newsapi has restrited max pageSize to 100 articles but still 10 articles per page for would be really nice.

I have built this pwa in golang and tailwind by using your api.Any feedback would mean a lot.

Regarding the DataUpdaterBot

Hi

Its not an issue, rather a question
I am just curious about the bot where it is deployed and how it is scheduled. From the first looks at repository, the bot is deployed on heroku, but not sure how periodic scheduling is enabled, heroku free dyno sleeps after sometime.

  1. may be a lambda
  2. or a cron job on some server?

How to use it in Retrofit 2

Hi owner, I am a beginner developer and only nows retrofit for network calls and fetching data, and I am unable to use this API in retrofit, actually the last param <country_code>.json is giving me a problem so can you add a sample code on how to use your API with the retrofit, currently I am using newspaper but it will expire soon

how do i make it store data in my own github repo

i have made a clone of your wonderful repo and i also created a .env file ..everything works but i am not able to upload all the files to my own repo . i have generated a personal access token and have updated it in .env but i am not able to upload it
i want to upload it to https://github.com/prakasharyaman/NewpaperNews-API .Please give me a little insight into it , would really appreciate it .
it says
<Response [404]>
my code:
def push_to_github(filename, content): url = "https://api.github.com/repos/prakasharyaman/NewpaperNews-API/contents" + filename base64content = base64.b64encode(bytes(json.dumps(content), 'utf-8')) data = requests.get(url + '?ref=main', headers={"Authorization": "token " + GITHUB_API_TOKEN}).json() print("trying to get data reply ")

sha = data['sha']
if base64content.decode('utf-8') != data['content'].replace("\n", ""):
    message = json.dumps({"message": "update " + filename,
                          "branch": "main",
                          "content": base64content.decode("utf-8"),
                          "sha": sha
                          })

    resp = requests.put(url, data=message,
                        headers={"Content-Type": "application/json", "Authorization": "token " + GITHUB_API_TOKEN})

    print(resp)
else:
    print("Everything up to date")

`

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.