 All right, I hope you're having fun while the whole world is shut down. I know I am so we're gonna have a little educational entertainment today We're gonna be writing a little shell script using this little tool. No, I should say on github right now There are a whole bunch of coronavirus tracker Repositories out there that are going viral so I've picked one of them and here's what I want to do I want to make a little script This this interface here. I should say gives you all this data about coronavirus I'm gonna make a little script that gives me just information about my local You know, how many coronavirus cases are near me in my state? And actually I'd like to be able to put it in my status bar just because why not just as an example something we can do So that's what we're gonna do here So here is a nice the reason I chose this repository to work with there are many of them It has a bunch of different data, but very nicely It has a CURL interface and that is a goldmine if you are using shell scripting to get what you want So to be clear, they have a website here that lists out all the data that you can look at the data on You know using this website now, of course It's not gonna render in your browser very well because you're really supposed to use it with CURL So let's actually do that. Let's go Let's go to another work space and we will see you RL that website and If we do that you see that we have this big output. It is downloaded to our command line and we have You know that the same thing we were just looking at In addition this particular this particular source you can give it country codes so for example if You know they have the example of Italy or the US or UK or something like that so we can do this We can say let's look at the regions of Italy and it will okay. Well, that one doesn't actually have any regions But whatever let's go to US and it will print out all the American states very nice Okay, so we get all this data and in my case now I'm gonna make it for my situation obviously you probably live in a different place than me, but I live in Florida, so What I want to do is I want to make a little status bar thing just for Florida Maybe I'll I mean I could add all other places to the to the same thing, but we'll just do it that way So first off so we don't have to re-download this over and over again. Actually, I'll plan it out I already have it in my head how it's gonna work out, but I'll tell you what I'm thinking about So the status bar script whether use it in the status bar now I want it to check. I want it to download every day the newest corona virus status And then display it whenever the script is run now first. We'll just work on displaying it So I'm just gonna pre-download this I'm gonna pre-download this file and I'm gonna put it in let's say cash Corona okay, just so it's out of my home directory because I don't like stuff in my home directory It's what a big pain So now we can just run, you know, we can just cat out cash corona or grep it directly or something like that So now we can see what it's looking like. So let's Grep the sequence Florida out of here. So here's what I want Actually, let's see. I should probably actually see What column each one of them is so I'm gonna grep out here's what I'm gonna do I want to see the line that says state and I also want to see the line that says Florida Because the line that says state lists out, you know, what the names of all the columns are, okay? I'll need that for now. All right. So here's what we're gonna do I'm gonna have I'm gonna have it list the confirmed cases and then maybe in Parentheses or something the daily change and then I'll have it list the mortality Maybe I'll have a little emoji skull next to that or no the deaths and then the mortality rate Maybe in parentheses or something. Okay, so that's well. We're all start So I'll start by actually making this. Well, let's let's make a proper script for this Let's not just do it in the command line. So let's say corona. It's gonna be a shell script Okay So we are gonna say this we're gonna say grep The sequence of state and the sequence of Florida I don't know why I don't just copy this over out of the cache file of corona Okay, so that's what we'll will where we will start and I'm gonna go ahead and Mark this as executable if I can spell it right sure mod corona Okay So now if we run corona, this is in my path. It will print out the things we just talked about right So now we can modify this script and let's add some stuff to it So first off I want to simplify this output because it's really it actually would be hard to manipulate With command line utilities because there's a lot of white space here I want to get rid of all the white space and we'll use said for that. Okay, we'll say this We'll say a said replace command and we're gonna replace I'm putting this on multiple lines. You can probably actually we'll put it on one line I won't confuse people too much. Let's say I'll replace Slash s means any white space and if I put the asterisk that means any amount of white space replace that with nothing. Let's just get rid of that and So if I run that now, it's gonna be all sort of mashed together and this is actually better for us I'll also looks like there's a weird character at the end. I don't even know how to type this thing So I'm gonna copy it over and I want to get rid of this So I'll have said also run a command. We'll say whenever you find this character just delete it Okay, so this says specifically substitute This character with the character in between these two slashes with it, which is nothing, okay So now that thing has been deleted and it's also this character here. It looks like a pipe. I don't think it is a pipe It's something a little bigger. I think it's like the box character Let's replace that with a semicolon because that's easier to manipulate. Okay, just let's just get rid of all the ugly characters Okay, so now we have this now you might say okay, how is this better? It's a little less readable to a human it is less readable to a human but but it's more readable to shell commands So here's what I want I want to cut out certain columns of data and I can you I can do that with cut The command cut so let's go over to our script and I'm gonna make a new line And I'm gonna say cut and I'm gonna first set a delimiter and I'm gonna say our delimiter is the semicolon All right, meaning the thing that divides all the columns is the semicolon So now I can say something like okay. Well show me what the second column is Okay, so if I run that it's gonna show just the second column or if I show You know the fourth column, right? Oops don't know why I entered on that. It'll show the fourth column or something like that So that's a pretty nice thing to do Actually now that I think about it We can make a little revision here that'll make things more efficient now I was gonna pipe cut into awk and awk will give you the ability to format it You know put parentheses around things put Icons emojis on things and print it out and whatever order you want But you know what we could actually just omit the cut because awk can do the same thing that cut does So as an example this line here we could change this to the following awk Let's say using the delimiter capital F is their delimiter thingy And instead say print Two and four and that should actually be exactly the same as cutting. Okay, so if we run that Missed something here. Let's see unterminant. Oh, yeah In that quote there. So that should be basically the same of course They don't add the delimiter in between them, but we actually prefer that we don't want the semicolons in our final answer So we can start messing with this. So just to be clear, let's double-check what our categories are again Okay, so we have confirmed cases blah blah blah blah Let's get all the ones that we actually want. Okay, so we're gonna want confirmed cases and that is one two three So that's column three and let's say We want the daily change in parentheses right after that. So that is gonna be confirmed as three That day one is what we want here. So let's say four five six seven eight nine Okay, so that's gonna be nine. Let's just check that that is right. Okay, so let's put it in a parenthesis So how you do that? You can just arbitrarily put strings into awk and it will Insert them so we can put an open parentheses. I'm putting a space before it and a closed parentheses right after it So now that is gonna have Now first off this line up here We only just have this line as Reminding us what each of the columns are we'll get rid of it in the second by getting rid of state from grep Okay, but we now have only this stuff here. Let's add some more stuff in I said I wanted the mortality rates and that's gonna be let's see if one day is nine Then mortality is gonna be seven actually when we want death rates to so that's gonna be five So I'm gonna put in after this. I'll say five and Seven just printing out our columns and let's put spaces and stuff between them. Let's say our death rate. Let's put the Let's put a little skull in front of it. So it looks deadly. Okay, and let's put The Mortality rate in parentheses. Okay, so we're gonna put that in parentheses open parentheses Close parentheses actually will put a little percentage sign Okay, so now If you look at this, okay, so we got our death rate. We got our deaths in Florida We have our mortality rate in Florida. We have our confirmed cases and we have the daily change actually Yeah, that looks pretty good. Okay. Actually, let's put another let's put another emoji in because why not? Let's say the isn't there like a medical face with a medical mask. There it is So let's put that in front of the At the very beginning, okay So now we'll have something like this. Okay, now I'm gonna go up I think we're about done So I'm gonna go up here and I'm gonna get rid of this line where I'm Grepping out where I'm searching for the line that says state because the only reason we're doing that is just so we have the Names of our columns. So now if I run it, this is all I'm gonna have great So that's basically what I want. So this is our cases in Florida the increase and the death and the mortality rate So now this is gonna be specific to my setup, but I'm going to integrate it Into my status bar and now again, I haven't added the ability to automatically update the script yet But I'm gonna add it to my status bar that happens to be in DWM blocks I don't know if anyone uses my dot files. You can do it this way, but otherwise. Let's see. I'm gonna have oops, I'm gonna have the I'll just copy one of these. I'll say it. What did I name the file? Just corona Okay, and I'm gonna give the update number to 14. All right. You don't know what that is. That's fine All right, so I'm gonna run that and I'm going to kill my status bar and start it back up and see what it looks like Okay Wait a second probably It'll show up Okay, there it is. Look at that. So there we have our little status bar thing showing how many are corona You know corona virus information So the last thing I want to do is obviously we just manually downloaded the data to this place right here cash corona But I want to put in a check basically that says whenever the script runs. Let's say that it It checks to see if we have an update From today checks to see if this file to be clear this file cash or yeah cash Corona it's gonna have metadata associated with it. Let's say. Oh, I was updated at this date Okay, so as an example we can look at that data by using the stat command We can say I guess stat. I think it's why no stat C Why that should give me the yes all the information about when this file was updated Okay, so now what I'm gonna do is I'm gonna cut out The first Column here, so that's gonna be This so we said our delimiter is the space And we're gonna cut out our first column format the first column So now we have the exact date that this file was opened. So I'm actually gonna I'm gonna have a little test. I'm gonna do have this in my script. I'm gonna say Well, well just write out what I have so far. I'm gonna check to see if this date is equal to the actual Date on your computer and if it is not it is going to up It's gonna redownload the original file. Okay, so we're gonna stat this we're gonna get the date and we're gonna say if What that is equal to Is equal to the following? I actually had to write down a date command because I know I'd use it because I always forget date syntax But here's what it looks like it is gonna be date Let's see plus Percent sign y for year and then month and then day. Okay, so that is that should be let's just test it just in case That should be our date. I put an equal sign in there. That was stupid So this will print out our actual date. So anyway, all this this say is we're gonna check we're gonna see if these two are equal is the Data of this files update equal to the date of the actual, you know, coronavirus Or the actual date that it is on your computer actually. Alright, so now we have the bare bones of a little check So now we just need to go back. Let's find our command where is corona Stats, okay, so there is the original command that we need to run So I'm gonna copy that and I'm gonna put it in here and here's what I'm gonna say if The date of the file is not equal to the current date. I put a Exclamation point in there so it's not here's what I'm gonna tell you to do the following See you are all that thingy and I'm gonna have it see you are all silently and put it in cash Corona, okay Alright, so let's be clear about what this is now. This is just one line. Well, okay Now it's one line, but very terse code But we be clear all this says is check to see if this file is equal to your current date and if it's not Download this okay, and put it there make it Make make it current make sure it's always updated So if we run this command multiple times, let's say I go out here and I just run corona And it's gonna show the output immediately because it's gonna check to see if this is equal It's gonna skip that statement, and it's going to go and print out You know the information it's supposed to but let's say we delete the corona Data file, okay, then if we run this it's gonna it's gonna give a little error and wait a little bit because it's downloading And it's gonna print out the information actually let's suppress that error because I don't even like that I don't want to see that I just wanted to give a little bit of time and then show The answer so let's cut let's say Let's pipe all of the potential error from this to dev null Okay Now let's double-check that so I'm gonna redelete our cache file. You're gonna run corona. Oops. I need to know okay I don't need to Send that to dev null. I need to send the stat command to dev null silly Silly me. Okay now. We'll check it. Okay remove the cache run corona. There it is All right, so that you saw there was a brief pause That was it downloading and then it immediately showed the information and if we rerun it Any time today as long as the date is the same. It's gonna keep displaying that now tomorrow when I run this It is going to redownload the information So when I log on to my computer and my status bar runs that the module will be updated Actually, maybe I should for DWM blocks user. Maybe users. Maybe I should just add Automatically updating time to it, but anyway, all right So that's about it. So just summing up everything all we did all we've been doing is we've been using basic commands like grep and said and awk and stuff like that to manipulate data But we've turned a nice little data interface like this into something you could use in a little script or a status bar And we have a nice little way of it updating a simple check just so you don't have to worry about it So anyway, that's about it another little long-winded video about a script tutorial, but I'm sure this will be useful to someone So enjoy it. See you guys it prepare for the next happening and I'll see you guys next time