The CovidNow website is designed by Henry Lim, Calum Lim, Sheng Han Lim, and Roshen Maghhan to collaborate with our Ministry of Health and the open data community. View more about the developer’s background at //covidnow.moh.gov.my/about/.
The new website covidnow.moh.gov.my is significantly better in terms of User Interface (UI) and User Experience (UX) compared with the existing covid-19.moh.gov.my/terkini-negeri, which has no longer been updated since the launch of the CovidNow website.
So, what is Open Data and how useful or important is Open Data?
Open Data is data that can be freely used, published, or distributed by anyone. Open data should also be easy to access and understand, leading to most data being published in .csv or excel format.
One of the reasons is that Open Data consumes a lot of time and resources. Since not all data can be published directly or raw, some sensitive data will need to be kept confidential. Hence, governments or organizations will need to filter or structure the data before being published openly.
The good about Open Data is that with the current technology, knowledge, and Data Science, we can use Open Data to get more insight or prediction. For example, how long will it take before the ICUs are overcrowded, given the rate of vaccine today? Or how long will we achieve herd immunity?
Of course, Open Data is not tied to only health care; it can be in every sector such as government, economy, society, organization, transport, and everything else!
The Open Data will surely help improve our quality of life, increase the performance and efficiency of public services, contribute to ideas for developing new business models or innovation services, improve social welfare, and more.
How to Extract/Import Data from COVIDNOW to Google Sheets?
To extract data such as the daily new cases or the vaccination rate, you can pull the data from the CovidNow website, which is relatively more straightforward, or directly from the source, Github.
To pull the data from Github, use the formula ImportHTML() with the Github URL and select Table 1. For example, when pulling the cases Malaysia data, use the formula below:
=Importhtml(“//github.com/MoH-Malaysia/covid19-public/blob/main/epidemic/cases_malaysia.csv”,”table”,1)
*You may encounter not enough column errors; just add more columns to the right.
To extract or import the data via the CovidNow website, you can use the formula ImportXML() or the UrlFetchApp.fetch() function inside Google App Script.
For the ImportXML() formula, you will need to learn how to use the XPath Query and inspect the HTML element of the CovidNow website (Press Ctrl+Shift+I for Google Chrome to inspect the element).
For example, if you wish to pull the daily new local cases data, use the formula: =index(IMPORTXML(“//covidnow.moh.gov.my/”,”//div[@class=’grid gap-0 sm:gap-2′]/div/div/div/div[@class=’chip bg-gray-300 px-2 font-semibold’]”),1,1)
The index() formula helps select the correct data to display, ignoring others after the ImportXML() formula that helps extract the data from the CovidNow website.
The XPath query can be understood as div[@class=’grid gap-0 sm:gap-2′] look for the <div> tag that has the class attribute of grid gap-0 sm:gap-2. Then we are going to select the <div> tag that is nested inside by inputting /div. Finally, we are going to select the <div> tag that has the class attribute of chip bg-gray-300 px-2 font-semibold.
As a result, you will get only the local new daily cases.
To access App Script in Google Sheets, go to Tools > Script Editor.
Then with the UrlFetchApp.fetch() function, you will need to copy down the sample below to the Script Editor and change yourself to suit your needs:
function getCOVIDNOW(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var res;
var data = UrlFetchApp.fetch("//covidnow.moh.gov.my/").getContentText();
try {
//Logger.log("data: "+data);
var values = data.match(/<div class="number flex justify-center gap-1.5"><div tabindex="-1" class="relative"><span>[0-9, \n]+/)[0]; //get total local cases value only
Logger.log("values: "+values);
var num = values.indexOf("\n")+1; //check for newline
Logger.log("num: "+num);
res = values.substring(num,values.length); //remove all html
res = res.match(/[0-9,]+/)[0]; //get numbers only
Logger.log("res: "+res);
} catch(e) {
res ="invalid";
}
ss.getRange("C5").setValue(res); //set value at cell C5
}
After that, insert a button to run the App Script by clicking on Insert > Drawings. Create your button in Google Drawings and press Save. Click on the 3 dots on the top right of the drawing and click Assign a Script. Input the script function name, for example, getCOVIDNOW. (If you have previously assigned a script and would like to change the function, press Ctrl on your keyboard while clicking the button.)
We also give out a copy of Google Sheets with a sample formula for importing data from GitHub and the CovidNow website via various ways, as stated above.
Copy the Google Sheets HERE. You can edit or view the script at Tools > Script Editor.
We hope this helps, and share this post if you think it could help more!
Follow us:
Telegram: t.me/cre8tivenow
Buy Me A Coffee (Click on Follow to get our updates directly sent to your mailbox for free!)
Facebook: facebook.com/cre8tivenow
Instagram: instagram.com/cre8tivenow
Email: sales@creativenow.my