Coder Social home page Coder Social logo

disease-sh / node-api Goto Github PK

View Code? Open in Web Editor NEW
62.0 62.0 24.0 228 KB

A JavaScript API Wrapper for NovelCOVID/API

Home Page: https://npmjs.com/novelcovid

License: Do What The F*ck You Want To Public License

JavaScript 100.00%
coronavirus data javascript library open-source wrapper

node-api's People

Contributors

3eif avatar akshatj27 avatar anishshobithps avatar apex2504 avatar apollyon600 avatar baruchvlz avatar chinhongtan avatar crazyuploader avatar dependabot[bot] avatar diced avatar ebwinters avatar leandroparedes avatar pujux avatar vinitshahdeo 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-api's Issues

NovelCovid 2.1.1

Thanks for a great library!

Currently my app has been using Version 1 via react JS

However Version 2 of NovelCovid does not seem to work.

Documentation: https://www.npmjs.com/package/novelcovid

Eg:

    const api = require("novelcovid");

    // you can choose which URL to use, this will not change the behaviour of the API
    api.settings({
      baseUrl: "https://disease.sh" | "https://api.caw.sh" | "https://corona.lmao.ninja",
    });
    debugger;
    // Any call to api() triggers an error
    api.all().then(console.log);

Error

CentraRequest.js:13 Uncaught TypeError: URL is not a constructor
    at new CentraRequest (CentraRequest.js:13)
    at push../node_modules/@aero/centra/createRequest.js.module.exports (createRequest.js:3)
    at fetchJson (index.js:3)
    at Object.countries (index.js:54)
    at eval (eval at UiContainer._this.setCountryData (UiContainer.js:119), <anonymous>:1:5)
    at UiContainer._this.setCountryData (UiContainer.js:119)
    at UiContainer.componentDidMount (UiContainer.js:171)
    at commitLifeCycles (react-dom.development.js:19814)
    at commitLayoutEffects (react-dom.development.js:22803)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at commitRootImpl (react-dom.development.js:22541)
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at commitRoot (react-dom.development.js:22381)
    at finishSyncRender (react-dom.development.js:21807)
    at performSyncWorkOnRoot (react-dom.development.js:21793)
    at scheduleUpdateOnFiber (react-dom.development.js:21188)
    at updateContainer (react-dom.development.js:24373)
    at react-dom.development.js:24758
    at unbatchedUpdates (react-dom.development.js:21903)
    at legacyRenderSubtreeIntoContainer (react-dom.development.js:24757)
    at render (react-dom.development.js:24840)
    at Module../src/index.js (index.js:12)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (serviceWorker.js:141)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

Thanks in advance

Error: invalid json response body at https://disease.sh/v2/historical/Brazil reason: Unexpected token < in JSON at position 0

Same error using the node-api HERE

Belgium is going well:
https://disease.sh/v2/historical/Belgium
Response header: content-type: application/json; charset=utf-8

Brazil is throwing this error:
https://disease.sh/v2/historical/Brazil
Response header: content-type: text/html; charset=utf-8

Error: invalid json response body at https://disease.sh/v2/historical/Brazil reason: Unexpected token < in JSON at position 0

Difference result for .countries() and .historical()

The code

import React, { Component } from 'react'
import { NovelCovid } from "novelcovid";

const covid = new NovelCovid();

export class Test extends Component {
 async componentDidMount(){
   const country = await covid.countries('usa')
   const history = await covid.historical(null, 'usa')
   console.log(country.deaths)
   const deaths = history.timeline.deaths
   console.log(deaths)
 } 
  render() {
    return (
      <div>

      </div>
    )
  }
}

export default Test

give two different result:
usa

I tried the same thing with 'russia', but it gives correct result
russia

0 instead of no value

First thanks for this wonderful api , I am new and your api helps me to make a project and get jobs
My issue is
Where there are no cases instead of 0 api return nothing which breaks my google charts
Error: Row 6 has 1 columns, but must have 2 at Object.gvjs_ll [as arrayToDataTable] at drawRegionsMap function

Please make it 0 instead of no value

Allow CORS

Great API!
Got this message while fetching data:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://corona.lmao.ninja/all. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
And It'll be more fun if CORS is enabled somehow 👍

sort by key not working for countries method

This is the code snippet i have used for accessing countries method with sort by key

exports.getTest = (req, res) => {
    (async() => {
        sortedCountries = await covid.countries('cases', 'sort by');
        res.send(sortedCountries);
    })();
}

Screenshot from 2020-04-16 21-23-55

But it returns that country not found.
I think there is some collision between sort and get specific country methods.

Fix "sort by" parameter in NPM package

I am using the latest version of the NPM package (1.1.2) and was experiencing the same issue that I have seen posted a few times that China was appearing at the bottom of the list, even though I was telling it to sort by cases:
await this.covid.countries(null, 'cases' );

Looking through the NPM package, it looks like I needed to explicitly add the sort= in the parameter:
await this.covid.countries(null, 'sort=cases' );

This works, but VS Code complains that this is wrong since the index.d.ts doesn't expect the sort=

Argument of type '"sort=cases"' is not assignable to parameter of type '"cases" | "todaysCases" | "deaths" | "recovered" | "active" | "critical" | "casesPerOneMillion" | "deathsPerOneMillion"'.ts(2345)

I assume this will be a quick fix in index.js changing
return node_fetch_1.default(${this.baseURL}/countries?${sort}).then(json);
to
return node_fetch_1.default(${this.baseURL}/countries?sort=${sort}).then(json);

P.S. Thanks for the fantastic API! 👍

Question

How can i make it check if the second argument after the command is an valid country?
like !covid sdfsdfsdfsdf
checks if sdfsdfsdfsdf is a valid country.
Coz when its not the message embed is all "undefined"

internal server error

We have faced internal server error from your API. Api stopped giving responses for a while. As we are using your API on a regular basis, it makes our work tougher if this kind of error occurs

NPM

Can you update it on NPM? Thanks :)

new version with all endpoints and filters

First thanks for your work.
I made a more complete version with more endpoints and filters, but I don't know how to update (I think that is an issue with the branch permissions ) and I let it here to you, if like this, upload the new version.
This is the index.js:

var _ = require('lodash');
/*
  Enjoy the new functions I have created! More coming soon if diced or elite makes useful updates
  - Apollo
*/
module.exports = {
    /**
     * @returns {fetch.Promise<Array.<Object>>|undefined}
     */
    all: async function () {
        // Wait why did you .toString() this function?
        const a = await require('node-fetch')(`https://corona.lmao.ninja/all`);
        return await a.json();
    },
    /**
     *
     * @param {?string} country
     * @returns {fetch.Promise<Array.<Object>>|undefined}
     */
    countries: async function (country) {
        // Wait why did you .toString() this function?
        if (!country) {
            const a = await require('node-fetch')('https://corona.lmao.ninja/countries');
            return await a.json();
        } else if (country) {
            try {
                const a = await require('node-fetch')(`https://corona.lmao.ninja/countries/${country}`);
                return await a.json();
            } catch (e) {
                return {error: 'Country not found'}
            }
        }
    },
    /**
     *
     * @param {?string} state
     * @returns {fetch.Promise<Array.<Object>>|undefined}
     */
    states: async function (state) {
        const a = await require('node-fetch')('https://corona.lmao.ninja/states');
        let data = await a.json();
        return state ? data.find(el => el.state === state) : data;
    },
    /**
     *
     * @param {?Object} filter f.e. {country : "China"}
     * @returns {fetch.Promise<Array.<Object>>|undefined}
     */
    jhucsse: async function (filter) {
        const a = await require('node-fetch')('https://corona.lmao.ninja/jhucsse');
        let data = await a.json();
        if (!filter) return data;

        filter = _.pick(filter, _(data).map(_.keys).thru(_.spread(_.union)).value());
        return _.filter(data, filter);
    }
}

and this is the new package.json

{
  "_from": "novelcovid@^1.0.5",
  "_id": "[email protected]",
  "_inBundle": false,
  "_integrity": "sha512-MHQNZ8h6b+2wu+sn7sSEtGTign/tr/SmsyLdc0EQ/dszE342o0Nqv+dAF+c2/VjAgnlSAQJpeDtmH3tvqU4byw==",
  "_location": "/novelcovid",
  "_phantomChildren": {},
  "_requested": {
    "type": "range",
    "registry": true,
    "raw": "novelcovid@^1.0.5",
    "name": "novelcovid",
    "escapedName": "novelcovid",
    "rawSpec": "^1.0.5",
    "saveSpec": null,
    "fetchSpec": "^1.0.5"
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/novelcovid/-/novelcovid-1.0.5.tgz",
  "_shasum": "9d8aa156584bc27cf6891c4c8c6bbdf2c3b3b6fa",
  "_spec": "novelcovid@^1.0.5",
  "_where": "E:\\wamp64\\www\\alexafiregoretest\\lambda",
  "author": {
    "name": "EliteDaMyth"
  },
  "bugs": {
    "url": "https://github.com/NovelCOVID/node-api/issues"
  },
  "bundleDependencies": false,
  "dependencies": {
    "node-fetch": "^2.6.0",
    "lodash": "^4.17.15"
  },
  "deprecated": false,
  "description": "An Api wrapper to get information about the Novel CoronaVirus.",
  "homepage": "https://github.com/NovelCOVID/node-api#readme",
  "keywords": [
    "coronavirus",
    "wrapper",
    "api"
  ],
  "license": "ISC",
  "main": "index.js",
  "name": "novelcovid",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/NovelCOVID/node-api.git"
  },
  "version": "1.0.5"
}

Update time

Hello, how often does the API update with the statistics?

Methods Not working

Below the code I was using to consume this api. It is not workig now. What changed suddenly?

const covid=require('novelcovid'); app.get('/api/states',(req,res)=>{ (async () => { let states = await covid.getCountry(); console.log(states); return res.json(states); })(); });

States Method for Each country

Could you please develop and publish a method to get states from each country. currently there is only one method to get the states specific to USA but not for all countries.

Typings are bad

The typings return an object, when it should return a promise of an object.

Not getting data

Not getting data for the last 2 days.
This is message received in JSON response
{"message":"This endpoint has been deprecated. Use /v2/all instead.","docs":"http://corona.lmao.ninja/docs"}
Is this repo still maintained ?

Add "types" to package.json

I think there should be property "types" in package json for Typescript import:
"types": "./dist/index.d.ts"

Add name argument filter for .states() method

The current API endpoint supports
https://corona.lmao.ninja/states/New%20York

However, for this package, it doesn't support filtering by a specific state

Suggestion:

  • Make this work like .countries('country name')
.state('state name');   // For Specific State

yesterday data issue

will you update the api?
async yesterday(country, sort) { if (country) { return node_fetch_1.default(`${this.baseURL}/v2/countries/${country}?yesterday=true`).then(json); } else if (!country && sort) { return node_fetch_1.default(`${this.baseURL}/v2/countries/${country}?yesterday=true${sort}`).then(json); } return node_fetch_1.default(`${this.baseURL}/v2/all?yesterday=true`).then(json); }
I changed urls in index.js file which in node_modules/novelcovid and it worked. i just looked at the NovelCOVID github source.

Province problem

historical(null, CountryName, CountryProvince) will never return info about that province only.

fetch(${this.baseURL}/v2/historical/${country}/${province}).then(json)

Can't do callbacks.

I'm trying to do a callback by using the

    api.continents().then(console.log);

Is their some way to do the .then but than say change the text of an html element to the array?

.countries(null, 'sort by'); Is not working

I have the following code

app.get('/countries', async (req, res) => {
	const { sort } = req.query;
	let countries;
	if (sort) {
		countries = await track.countries();
	} else {
		countries = await track.countries(null, sort);
	}
	res.send(countries);
});

But the answer is always the same, even if I send the sort parameter

image

question

I don't believe this is an issue on your end but if I do this code for United States I still get the results for the .getAll()

const all = await covid.getAll();
const state = await covid.getState({ state: args.splice(1).join(` `) });
const country = await covid.getCountry({ country: args.splice(1).join(` `) });
if (!args[1]) {
    console.log(all);
} else if (args[0] === `state`) {
    console.log(state);
} else if (args[0] === `country`) {
    console.log(country);
}

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.