<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vishnu Ks</title>
    <description>The latest articles on DEV Community by Vishnu Ks (@hackerkid).</description>
    <link>https://dev.to/hackerkid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F90353%2F2e5cf1b5-42d7-416c-92b7-a47407e8a25c.jpg</url>
      <title>DEV Community: Vishnu Ks</title>
      <link>https://dev.to/hackerkid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hackerkid"/>
    <language>en</language>
    <item>
      <title>Building A Real-Time Covid-19 Tracker Using Google Sheets</title>
      <dc:creator>Vishnu Ks</dc:creator>
      <pubDate>Wed, 01 Apr 2020 14:30:39 +0000</pubDate>
      <link>https://dev.to/hackerkid/building-a-real-time-covid-19-tracker-using-google-sheets-5g2p</link>
      <guid>https://dev.to/hackerkid/building-a-real-time-covid-19-tracker-using-google-sheets-5g2p</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BaPXiBRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-19-35-21-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BaPXiBRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-19-35-21-1.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I was not a big fan of Google Sheets till a few days back. I mean how excelited  can you get about a spreadsheet software? Then I found out that Google Sheets can run JavaScript and do cron jobs. Yeah. You didn't misread that. If you are surprised like I was, continue reading. I will show how to write and execute Javascript and run Cron jobs in Google Sheets by building a Covid-19 tracker in less than 15 mins. The idea behind the blog post is to demonstrate how powerful Google Sheet Ecosystem is and how you can build some of your side projects on top of it without writing a ton of code.&lt;/p&gt;

&lt;p&gt;For simplicity, we will build a tracker that tracks the total number of cases globally. We need 3 components for building this.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Google Sheet to store the date and cases reported.&lt;/li&gt;
&lt;li&gt;Keeping Google sheets in sync with real-time data&lt;/li&gt;
&lt;li&gt;Displaying data from Google Sheets as an Interactive Graph.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. A Google Sheet to store the date and number of cases
&lt;/h3&gt;

&lt;p&gt;The first thing we need to create is a Google sheet to store the data. You can create a new sheet by going to &lt;a href="https://sheet.new"&gt;https://sheet.new&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Use column A of the sheet storing the date and column B for storing the total number of cases reported so far. Now go ahead and name the column A as &lt;code&gt;date&lt;/code&gt; and column B as &lt;code&gt;cases&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HN4DrV7b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-16-39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HN4DrV7b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-16-39.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to populate the sheet with the historical data of Covid-19 cases. For that, we can use the following API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://corona.lmao.ninja/v2/historical/all"&gt;https://corona.lmao.ninja/v2/historical/all&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This API returns the global historical data of Covid-19. You can click on the link to see how the response would look like.&lt;/p&gt;

&lt;p&gt;But how do you fetch the data from the API and insert it into Google Sheets?&lt;/p&gt;

&lt;p&gt;For that, we can make use of &lt;code&gt;Google AppsScript&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Google AppsScript is a rapid application development platform that makes it fast and easy to create business applications that integrate with G Suite.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If that doesn't make much sense, you can think of AppsScript as a code editor in which you can run and execute Javascript. It comes with preinstalled libraries that you can use for reading and editing data in GSuite products.&lt;/p&gt;

&lt;p&gt;You can access the AppsScript code editor by opening the &lt;code&gt;Tools&lt;/code&gt; menu and clicking on &lt;code&gt;Code Editor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CyJT6KV3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/03/Screenshot-from-2020-03-30-17-10-26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CyJT6KV3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/03/Screenshot-from-2020-03-30-17-10-26.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;AppScript Code Editor&lt;/p&gt;

&lt;p&gt;Now copy-paste the following code to the editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getHistoricalData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://corona.lmao.ninja/v2/historical/all&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;UrlFetchApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cases&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;populateHistoricalData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;SpreadsheetApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getActive&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getSheetByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sheet1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;historicalData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getHistoricalData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;historicalData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cases&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;historicalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendRow&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cases&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The code will make a request to &lt;a href="https://corona.lmao.ninja/v2/historical/all"&gt;&lt;code&gt;https://corona.lmao.ninja/v2/historical/all&lt;/code&gt;&lt;/a&gt;, fetch the result, parse and store it in your Google Sheet.&lt;/p&gt;

&lt;p&gt;Save the code by pressing the Save option in File menu. After that choose &lt;code&gt;populateHistoricalData&lt;/code&gt; as the default function to execute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uioqsCq9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-29-01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uioqsCq9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-29-01.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;Choosing the default function to execute&lt;/p&gt;

&lt;p&gt;Now click on the run ▶️ button. This will run &lt;code&gt;populateHistoricalData&lt;/code&gt; function. The function would populate the Google sheet with the historical data from the API. If everything works fine your sheet would look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SuWMY0vc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-31-49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SuWMY0vc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-31-49.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Keeping Google sheets in sync with realm time data
&lt;/h3&gt;

&lt;p&gt;The data we have inserted in the Google Sheets is historical and doesn't include the cases of the current day.  So we need to figure out a way to keep the sheet updated.&lt;/p&gt;

&lt;p&gt;We can do this is by making requests every few minutes to an API that returns the latest data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://corona.lmao.ninja"&gt;https://corona.lmao.ninja&lt;/a&gt; &lt;strong&gt;/all&lt;/strong&gt; is such an API.&lt;/p&gt;

&lt;p&gt;The following code makes requests to &lt;code&gt;https://corona.lmao.ninja/all&lt;/code&gt; and update today's count.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getTotalCasesSoFar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://corona.lmao.ninja/all&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;UrlFetchApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;jsonResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;casesSoFar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jsonResponse&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cases&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;casesSoFar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;updateTotalCasesToday&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;SpreadsheetApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getActive&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getSheetByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sheet1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todayDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setHours&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastRowId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getLastRow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getRange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastRowId&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;getValue&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;casesSoFar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getTotalCasesSoFar&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lastDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;oldCountCell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getRange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastRowId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;oldCountCell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;casesSoFar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendRow&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;casesSoFar&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Copy and paste the code below our existing code in the script editor. Now choose &lt;code&gt;updateData&lt;/code&gt; as the default function and click run. If all goes well, you can see a new row getting inserted which contains today's date and cases so far. If you run the code again it will try to update cases by making another request to the API. An update occurs if there is a change in number.&lt;/p&gt;

&lt;p&gt;Now that we have the code ready for keeping the data in sync, we need to figure out a way to run this code automatically. It's not ideal for us to click on the Run ▶️ button every few minutes. What we need is a  cron job that runs this script every few minutes. For that, we can make use of &lt;code&gt;Triggers&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Open edit menu and click on &lt;code&gt;Current project's triggers&lt;/code&gt;. This will open a dashboard that looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dvDMiMBK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/03/Screenshot-from-2020-03-30-17-12-44.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dvDMiMBK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/03/Screenshot-from-2020-03-30-17-12-44.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can create a new trigger by clicking one &lt;code&gt;create a new trigger&lt;/code&gt;.  This will open a form. Set the function as &lt;code&gt;updateTotalCasesToday&lt;/code&gt; and event source as &lt;code&gt;Time-driven&lt;/code&gt; . You can set the &lt;code&gt;minute interval&lt;/code&gt; as you like. In my case, I have set it to every 10 minutes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Zt9iCRw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-39-46.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Zt9iCRw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-39-46.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;code&gt;Save&lt;/code&gt; to create the Trigger.  &lt;/p&gt;

&lt;p&gt;Voila! Google Apps Script will invoke the function every few minutes.&lt;/p&gt;

&lt;p&gt;Now that our sheet is in sync with the latest data, let's proceed to the final step.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Displaying data from Google Sheet as an Interactive Graph
&lt;/h3&gt;

&lt;p&gt;For that, we can make use of Google Data Studio. Google Data Studio is a product used for making interactive reports and dashboards. We can use it for creating a time series graph from our Google Sheet.&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://datastudio.google.com/"&gt;https://datastudio.google.com/&lt;/a&gt; and create a new report.&lt;/p&gt;

&lt;p&gt;Now choose Google Sheets as your data source and choose the Sheet that you created in the previous step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gvJs-wV8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-46-26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gvJs-wV8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-46-26.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now click on &lt;code&gt;Insert&lt;/code&gt; menu and select &lt;code&gt;Time series&lt;/code&gt;. This will insert a graph to your report.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O--g0aZS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-19-59-09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O--g0aZS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-19-59-09.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now in the right side bar set the value of &lt;code&gt;Date Range Dimension&lt;/code&gt; to &lt;code&gt;Date&lt;/code&gt; and &lt;code&gt;Dimension&lt;/code&gt; to &lt;code&gt;Date&lt;/code&gt; column. Set the value of Metric to &lt;code&gt;Cases&lt;/code&gt; and choose the &lt;code&gt;Max&lt;/code&gt; aggregator. Max aggregator uses the maximum of cases values, if there are more than one rows with the same date.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZtAUOhl6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-52-32-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZtAUOhl6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-18-52-32-1.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The report should now contain a time-series graph.&lt;/p&gt;

&lt;p&gt;You can also insert  a &lt;code&gt;Date range&lt;/code&gt; that allows users to change the date range. For that click on insert and then choose &lt;code&gt;Date range&lt;/code&gt;. The final result would look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qeLj70kC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-19-35-21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qeLj70kC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.vishnuks.com/content/images/2020/04/Screenshot-from-2020-04-01-19-35-21.png" alt="Building A Real-Time Covid-19 Tracker Using Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can share the report with anyone by clicking on Share. See the link below to see how will the report looks like when shared with someone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://datastudio.google.com/open/14nOy1s9OWDxNRsGjPHFD1FqyO5MQqT-y"&gt;https://datastudio.google.com/open/14nOy1s9OWDxNRsGjPHFD1FqyO5MQqT-y&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also embed the report in any website by clicking on the &lt;code&gt;File&lt;/code&gt; menu and choosing &lt;code&gt;Embed report&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Great. We have now built a Covid-19 tracker. To recap&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We learned how to manipulate Google Sheets using JavaScript.&lt;/li&gt;
&lt;li&gt;How to run cron jobs using Triggers.&lt;/li&gt;
&lt;li&gt;How to create interactive graphs using Google Data Studio.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tutorial is only for demonstration purposes. I would not use the code, data, etc in production without doing due diligence.  Hope this blog post was helpful :)&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>covid19</category>
      <category>visualization</category>
    </item>
    <item>
      <title>Publishing your dev.to blog posts to diff.blog</title>
      <dc:creator>Vishnu Ks</dc:creator>
      <pubDate>Tue, 09 Jul 2019 16:35:45 +0000</pubDate>
      <link>https://dev.to/hackerkid/publishing-your-dev-to-blog-posts-to-diff-blog-4n07</link>
      <guid>https://dev.to/hackerkid/publishing-your-dev-to-blog-posts-to-diff-blog-4n07</guid>
      <description>&lt;p&gt;diff.blog is an aggregator of developer and engineering blogs. I built it after I was having a hard time finding good developer blogs to follow. diff.blog makes it super easy to find and follow amazing developer blogs from all over the internet. &lt;/p&gt;

&lt;p&gt;If you have not yet included your dev.to blog to diff.blog now is the perfect time. Adding your blog to diff.blog is pretty simple and hardly takes a minute.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://diff.blog"&gt;https://diff.blog&lt;/a&gt; and create your account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to blog settings by opening &lt;a href="https://diff.blog/account/settings/blog/"&gt;https://diff.blog/account/settings/blog/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now enter this url in the input box.&lt;br&gt;
&lt;code&gt;https://dev.to/feed/&amp;lt;username&amp;gt;&lt;/code&gt;&lt;br&gt;
Make sure to replace your &lt;code&gt;&amp;lt;username&amp;gt;&lt;/code&gt; with your dev.to username&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7pYC6f_v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fk7a7q3n2nqvsajaoq7y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7pYC6f_v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fk7a7q3n2nqvsajaoq7y.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finally click the save button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🎉 Congrats. You have added your blog to &lt;a href="https://diff.blog"&gt;https://diff.blog&lt;/a&gt;. New blog posts would appear on diff.blog as you publish them on dev.to. If you have any questions ask me in the comment section. To learn more about diff.blog visit &lt;a href="https://diff.blog/FAQ/"&gt;https://diff.blog/FAQ/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>writing</category>
    </item>
  </channel>
</rss>
