PHP Classes

PHP Corona Virus Database: An API to lookup information about Corona Virus

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 238 All time: 8,054 This week: 206Up
Version License PHP version Categories
coronavirusdatabase 1.0.0GNU General Publi...5PHP 5, Statistics, Web services, Biology
Description 

Author

This package provides an API to lookup information about Corona Virus.

It can provides API entries to perform queries on a database with figures about the current status of the Corona Virus epidemic around the world. Currently it can:

- Return the number of reported cases
- Return the number of reported deaths
- Return the number of recovered people
- Filter the results by country
- Return results aggregating all countries

Innovation Award
PHP Programming Innovation award nominee
March 2020
Number 6
The Corona Virus pandemia has been an important event mainly in the year of 2020 that affected the lives of many people around the world.

This package provides an API that returns useful information about this pandemia. Using this API, it becomes easier to implement applications that need information about the pandemia to provide an useful service.

Manuel Lemos
Picture of Max Base
  Performance   Level  
Name: Max Base <contact>
Classes: 5 packages by
Country: United States United States
Age: ???
All time rank: 2602358 in United States United States
Week rank: 170 Up21 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Example

<?php
define
("BASE", __DIR__ . "/");
require_once
"_core.php";

if(!
function_exists("getallheaders")) {
   
// Probably you are in CLI and it's not usefull!
    // But sometimes it's usefull for some webserver!
   
function getallheaders() {
       
$headers = [];
        foreach(
$_SERVER as $name => $value) {
            if(
substr($name, 0, 5) == "HTTP_") {
               
$headers[str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($name, 5)))))] = $value;
            }
        }
        return
$headers;
    }
}
function
preapreItems($items) {
    foreach(
$items as $i=>$array) {
        if(isset(
$array["id"])) {
           
$array["id"]=(int) $array["id"];
        }
        if(isset(
$array["totalCase"])) {
           
$array["totalCase"]=(int) $array["totalCase"];
        }
        if(isset(
$array["totalDeath"])) {
           
$array["totalDeath"]=(int) $array["totalDeath"];
        }
        if(isset(
$array["totalRecovered"])) {
           
$array["totalRecovered"]=(int) $array["totalRecovered"];
        }
       
$items[$i]=$array;
    }
    return
$items;
}
function
supportSort($table, $clauses, $data) {
    global
$db;
   
$items=[];
    if(isset(
$data["sort"])) {
       
$sort=$data["sort"];
       
$type="DESC";
        if(isset(
$data["type"])) {
           
$t=strtolower($data["type"]);
            if(
$t == "asc" || $t == "desc") {
               
$type=$t;
            }
            else {
               
display(["status"=>"failed", "message"=>"Sort type is not valid and not allowed!"]);
            }
        }
       
$fields=["id","name","totalCase","totalDeath","totalRecovered","datetime"];
        if(
in_array($sort, $fields)) {
           
$items=$db->selects($table, $clauses, "ORDER BY `". $sort ."` ".$type);
        }
        else {
           
display(["status"=>"failed", "message"=>"Sort field value is not valid and not allowed!"]);
        }
    }
    else {
       
$items=$db->selects($table, $clauses);
    }
    return
$items;
}

$headers=getallheaders();
if(
$headers != null && is_array($headers) and count($headers) > 0) {
    if(isset(
$headers["Token"])) {
       
$token=$headers["Token"];
       
$tokenItem=$db->select("token", ["token"=>$token]);
        if(
$tokenItem == null) {
           
display(["status"=>"failed", "message"=>"This token is not valid!"]);
        }
        else {
            if(
$tokenItem["getAccess"] == 0 and $tokenItem["postAccess"] == 0) {
               
display(["status"=>"failed", "message"=>"You did not access to webservice using GET and POST method!"]);
            }
            else if(
$tokenItem["getAccess"] == 0 and $tokenItem["postAccess"] == 1) {
               
$data=$_POST;
            }
            else if(
$tokenItem["getAccess"] == 1 and $tokenItem["postAccess"] == 0) {
               
$data=$_GET;
            }
            else if(
$tokenItem["getAccess"] == 1 and $tokenItem["postAccess"] == 1) {
               
$data=$_GET;
                foreach(
$_POST as $key=>$value) {
                   
$data[$key]=$value;
                }
            }
            if(isset(
$data["method"])) {
               
$method=$data["method"];
                if(
$method == "total") {
                    if(
$tokenItem["canTotal"] == 1) {
                       
$all=$db->sum("country", "totalCase");
                       
$died=$db->sum("country", "totalDeath");
                       
$recov=$db->sum("country", "totalRecovered");
                       
display(["status"=>"success", "message"=>"", "result"=>["all"=>$all, "died"=>$died, "recovered"=>$recov]]);
                    }
                    else {
                       
display(["status"=>"failed", "message"=>"Sorry, you did not have access to this method!"]);
                    }
                }
                else if(
$method == "country") {
                    if(
$tokenItem["canFilter"] == 1) {
                        if(isset(
$data["query"])) {
                           
$items=$db->select("country", ["name"=>$data["query"]]);
                           
$items=preapreItems([$items]);
                            if(isset(
$items[0]) and $items[0] != "") {
                               
$items=$items[0];
                            }
                            else {
                               
$items=null;
                            }
                           
display(["status"=>"success", "message"=>"", "result"=>$items]);
                        }
                        else {
                           
display(["status"=>"failed", "message"=>"Query value is not avaible!"]);
                        }
                    }
                    else {
                       
display(["status"=>"failed", "message"=>"Sorry, you did not have access to this method!"]);
                    }
                }
                else if(
$method == "search") {
                    if(
$tokenItem["canSearch"] == 1) {
                        if(isset(
$data["query"])) {
                           
// $items=$db->selects("country", ["name"=>["LIKE", "and", "%".$data["query"] . "%"]]);
                           
$items=supportSort("country", ["name"=>["LIKE", "and", "%".$data["query"] . "%"]], $data);
                           
$items=preapreItems($items);
                           
display(["status"=>"success", "message"=>"", "result"=>$items]);
                        }
                        else {
                           
display(["status"=>"failed", "message"=>"Query value is not avaible!"]);
                        }
                    }
                    else {
                       
display(["status"=>"failed", "message"=>"Sorry, you did not have access to this method!"]);
                    }
                }
                else if(
$method == "list") {
                    if(
$tokenItem["canView"] == 1) {
                       
$lastTime=$db->select("country", [], "ORDER BY `datetime` DESC");
                       
// $items=$db->selects("country");
                       
$items=supportSort("country", [], $data);
                       
$items=preapreItems($items);
                       
display(["status"=>"success", "message"=>"", "lastUpdate"=>$lastTime["datetime"], "result"=>$items]);
                    }
                    else {
                       
display(["status"=>"failed", "message"=>"Sorry, you did not have access to this method!"]);
                    }
                }
                else {
                   
display(["status"=>"failed", "message"=>"Method type is not valid!"]);
                }
            }
            else {
               
display(["status"=>"failed", "message"=>"Every request in this webservice need a method type!"]);
            }
        }
    }
    else {
       
display(["status"=>"failed", "message"=>"You did not have access to this webservice without token!"]);
    }
}
else {
   
display(["status"=>"failed", "message"=>"You did not have access to this webservice!"]);
}


Details

PHP Corona Virus Database

An API to lookup information about Corona Virus

This package provides an API to lookup information about Corona Virus.

It can provides API entries to perform queries on a database with figures about the current status of the Corona Virus epidemic around the world. Currently it can:

  • Return the number of reported cases
  • Return the number of reported deaths
  • Return the number of recovered people
  • Filter the results by country
  • Return results aggregating all countries

Corona Virus Database

A repository for analyzing references and database of gisanddata.maps.arcgis.com website for Corona Virus.

Corona Virus

Website: https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6

Downloadable database: GitHub: Here.

There is a csv files for every day. e.g: https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data

But main site has not get data from that.

By checking main website, I did check all requests and links:

Finaly I found this:

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/2/query?f=json&where=Confirmed%20%3E%200&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc&resultOffset=0&resultRecordCount=1000&cacheHint=true

But you can see all requests as HAR format at here.

Features

  • Free, Open Source, Easy and short code
  • Ability to create token for suers
  • Ability to search in country
  • Ability to sort (ASC or DESC) in country list
  • Ability to get total number (in world)
  • Ability to limit auth and token

Description

This project is a web service that allows you to create different accesses.

And later use this web service in different applications and sites. e.g: You may even sell a subscription to this web service.

All request of this web-service will need a token for Auth and access to methods.

There is a table for tokens, called token. So you can create one token or more.

In READMD.me file, I explain how can use from web service.

So others can using this key to access to this web-service.

You will need to execute $ php _update.php update in src/ directory to insert and updates data into your database, then you can use from API methods. (You should pass token value in Headers)

Remember it's a API service, if are you looking for a script to display directly list of corona cases, you can check below repositories:

https://github.com/BaseMax/api-webservice-COVID-19/

https://github.com/BaseMax/CoronaVirusOutbreakAPI/

Using

Create a token in database:

screen2.jpg

Development Mode

In additation of my message: If you want to use this API webservice, And want to easily see response of methods.

You can use a plugins in your browser. such as: https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en

You had to add Token header with a value.

screen1.jpg

COVID19 API

All request need token value in header, You can create token in token table.

Country List

GET: http://localhost/CoronaVirusDatabase/src/?method=list

POST: http://localhost/CoronaVirusDatabase/ with method=list data

{
	status: "success",
	message: "",
	lastUpdate: "2020-02-27 18:05:06",
	result: [
		{
		id: 1,
		name: "china",
		totalCase: 78514,
		newCase: 450,
		totalDeath: 2747,
		newDeath: 32,
		totalRecovered: 32954,
		seriousUser: 8346,
		datetime: "2020-02-27 18:05:03"
		},
		...
	]
}

Country List with Sort

DESC sort:

GET: http://localhost/CoronaVirusDatabase/src/?method=list&sort=totalCase&type=desc

POST: http://localhost/CoronaVirusDatabase/ with method=list&sort=totalCase&type=desc data

or ASC sort:

GET: http://localhost/CoronaVirusDatabase/src/?method=list&sort=totalCase&type=asc

POST: http://localhost/CoronaVirusDatabase/ with method=list&sort=totalCase&type=asc data

Search in country

GET: http://localhost/CoronaVirusDatabase/src/?method=search&query=ir

POST: http://localhost/CoronaVirusDatabase/ with method=search&query=ir

{
	status: "success",
	message: "",
	result: [
		{
			id: 5,
			name: "iran",
			totalCase: 245,
			newCase: 106,
			totalDeath: 26,
			newDeath: 7,
			totalRecovered: 25,
			seriousUser: 0,
			datetime: "2020-02-27 16:05:56"
		},
		{
			id: 24,
			name: "iraq",
			totalCase: 6,
			newCase: 1,
			totalDeath: 0,
			newDeath: 0,
			totalRecovered: 0,
			seriousUser: 0,
			datetime: "2020-02-27 16:05:59"
		}
	]
}

Search in country with sort

GET: http://localhost/CoronaVirusDatabase/src/?method=search&query=ir&sort=totalCase&type=asc

POST: http://localhost/CoronaVirusDatabase/ with method=search&query=ir&sort=totalCase&type=asc data

Total numbers in all country and in the world

GET: http://localhost/CoronaVirusDatabase/src/?method=total

POST: http://localhost/CoronaVirusDatabase/ with method=total

{
	status: "success",
	message: "",
	result: {
		all: "163492",
		died: "5588"
	}
}

Installing / Using from COVID19 API

  • Download source files
  • Upload sources files in a webserver (e.g: `/var/www/html` or `/usr/share/nginx/html` or ...)
  • Create a database for this project
  • Put username, password and database name in `_core.php` file and config this project by modify `_core.php` file
  • Import `corona.sql` file into your database (using phpmyadmin or mariadb, mysql cli or other tools)

> Note: corona.sql is database structure with empty table, you will use it to setup this project. But output.sql is a database output with current corona data.

How keep data live and up to date?

Run $ php _update.php update every time you want to update your database rows. It will automaticly update and change data, if they are new or changed!

Using crontab to automaticly update results

Crontab command: /2 * php _update.php >/dev/null 2>&1

Current time is: 2020-02-26 7:29:00 PM UTC

This cron job will be run at: (5 times displayed and more...)

  • 2020-02-26 20:00:00 UTC
  • 2020-02-26 20:01:00 UTC
  • 2020-02-26 20:02:00 UTC
  • 2020-02-26 20:03:00 UTC
  • 2020-02-26 20:04:00 UTC
  • ...

COVID-19 CORONAVIRUS OUTBREAK

Corona Virus Outbreak API

A tiny and small program to crawler and analyze outbreak of COVID-19 in world and every country using PHP.

Confirmed Cases and Deaths by Country, Territory, or Conveyance

The novel coronavirus COVID-19 is affecting 45 countries and territories around the world and 1 international conveyance (the "Diamond Princess" cruise ship harbored in Yokohama, Japan).

The bulk of China's new cases and deaths are reported after 22:00 GMT (5:00 PM ET) for Hubei (lately with delays of up to 2 hours), and after 00:00 GMT (7:00 PM ET) for the rest of China (lately with delays of up to 9 hours).

Max Base

My nickname is Max, Programming language developer, Full-stack programmer. I love computer scientists, researchers, and compilers. (Max Base)

Asrez Team

A team includes some programmer, developer, designer, researcher(s) especially Max Base.

Asrez Team


  Files folder image Files (12)  
File Role Description
Files folder imagesrc (5 files)
Accessible without login Plain text file corona.sql Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file output.sql Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file response.json Data Auxiliary data
Accessible without login Image file screen1.jpg Data How create a token in database?
Accessible without login Image file screen2.jpg Data How to directly see response of methods, using a plugin in chrome.

  Files folder image Files (12)  /  src  
File Role Description
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file _core.php Example Example script
  Accessible without login Plain text file _netphp.php Aux. Auxiliary script
  Plain text file _phpedb.php Class Class source
  Accessible without login Plain text file _update.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:238
This week:0
All time:8,054
This week:206Up