 Okay. Today we're going to be looking at the weather in our show. Now, I've done this before, but we're just going to go over a few little different things. So you can use curl or I'm going to use W get just because it's on more systems. I'm using dash Q means quiet. It's not going to give out the download information and dash O, capital O dash means send it to standard output. So it's going to display what it gets on the screen rather than sending it to a file. Now, if I was to point it at this URL here, it is going to give me a nicely color coded formatted weather for my current location based on my IP address. You can request other information and other locations if you want. I have whole videos on that. Just go to my website, film site Chris and search weather and you'll probably find it. And that's great. But we're going to use information from this service to create our own little interface that could be used in our applications in case you want to display the weather in your applications. So let's go ahead and what we're going to do make us a little bigger, run the same thing. We're going to go against the same URL, but we're going to say question mark format. So we're going to tell it we want to format what format we want J1 and that's going to give us some nicely formatted JSON output. JSON is great for using applications. It separates up the information. It gives us all that information we just saw, but formatted so that we can use it how we want. Now, with that, you go through and you can like grab or awk and cut for what you want. But if you have available, we're going to use the JQ command should be in your repositories on most distributions. If I just pipe what's there into JQ and dot, what's going to do is if it isn't formatted in line, like sometimes you get JSON is all on one line, it will format it so it's readable and also color coded. So right there we have that. If we take that, we can also pass into it other information. So I can say instead of just dot, I can say dot and then quotations, I can ask for something from that list. So I can read through that, see all the variables and I'm going to say condition, making sure that I spell everything right. And that's an array. I want the first one in the array. So I'm going to say zero there and that will just give me right here the current information. So now I can request whatever I want from here. I can get the current temperature in Celsius Fahrenheit. I can get what it feels like rather than the actual temperature humidity. I can get the description, which right now it's saying it's partially cloudy. Great. I can get the wind direction and speed and both miles and kilometers per hour. So great. We can grab whatever we want. Today, we're going to be looking at getting the temperature in Fahrenheit, the humidity percentage and the value of the weather description. And let's go ahead and start working on that. Now doing that here at the shell, I could add on to this. So we've grabbed that information and I can say a little pipe symbol and start requesting more information. So I can say dot temp underscore capital F and that will give me the temperature in Fahrenheit. If I was to add to this command, I can do dash R and it will remove those quotations in case I don't want those in my command, depending on how you're coding things out. I can actually request multiple things. So I can put this in parentheses here and then divide things up by comma. So I can say comma dot humidity and if I spelt that right, oh, I put two M's. There we go. Now I've got the temperature and humidity. So I can grab that. What I'm going to do is I'm going to grab those three things I want and put them in variables. But let's start by creating a script here. So I'm going to use Vim as my text editor. Use whatever editor you want, as long as it's a text editor and not a Word document editor. I'm going to just call it weather.sh. It is going to be a shell script. So I'm going to give, or a bash script. So I'm going to give it its shebang line of bin bash there. And we're going to start. I'm going to put things into variables here. I'm going to put the URL into a variable called URL. And then I'm going to grab that information. Now I'm going to put the JSON. And I'm going to request stuff from the server once and put it into a variable called JSON. That way I can manipulate it multiple times without pinging the server multiple times, because there will be a limit of number of times. If you start hitting their server all the time, they're going to block you for a while. And all websites are pretty much going to do that because they don't want you dragging down their server. Now before we did our wget command, we did it here and we're putting in a variable. So now I have to do is echo out that JSON into our jq command. And so I can do this if I want to get temperature and Fahrenheit. Now I'm going to throw that into a variable. I'm going to call the variable temp for temperature, although writing out temperature might be better because temp might mean like a temp file. But I'm going to go ahead and do this. I'm going to put that in dollar sign parentheses, meaning I want the output of that command and don't forget the quotation mark there. Whatever the output of this command is, we're going to put it into our temperature variable. I am going to do the same thing for humidity and the same thing for our weather description. At this point, I can now echo out some output. I can say it's or it is currently and I'll say dollar sign and I can do description. You can also put this in squiggly brackets, I have videos on why you may want to do that in this particular case, it doesn't really matter, but it's good to get in the habit of in first or reasons that I'm not going to go over in this field. Now that I've saved that, I'm going to make it executable. You only have to do this one time on each system you copy it to. I run that and if I did everything right, it says that it's partially cloudy. Great. I can go back into my code here. I can do another line. I can say echo and I'm going to say temperature. Oh, I spelled things right to put a P in there. That's what's wrong. There we go. Temperature and I'm going to say dollar sign, close my quotations, I'm going to run that and we'll give it to me. It says 80. Is it Fahrenheit or is it Celsius and what I'm going to do is if you go online and search Unicode degrees Fahrenheit degrees Celsius, it will give you that and just copy and paste it. That's what I normally do to get special characters like this. All I'm going to do is I'm going to copy that and I'm going to paste it right in there. Now I have degrees Fahrenheit symbol. That's not a degree F, it's actually one character, but here we have that. Perfect. I'm going to go back in there now and I'm going to add a line that echoes out humidity percent. I'm just going to say that. Now we have this and our code is done. If you want to stop watching now, you can stop watching now. We're going to make it a little bit better, a little bit prettier, making it look nice. We're going to add in some variables up here, a color library. I'm just going to copy and paste some things here. What we're doing here is using escape codes. Escape codes are these right here. That will allow us to make the font do different things. Make it different colors, make it flash, make it bold, do a background color a different way. I have videos on this. If you actually go to my website, filmsbychrist.com, and you just type in color, you'll probably see a few here for bash. We have bash escape codes. That one will work. I have one here, and here's another one, bash colors, and then here, this one where it says bin bash, bin bash, bin bash, and it says color variables. I think that's the one where I go over creating a library similar to what I'm doing here. That way you can use those variables. Now, if we want to color something, for example, if I want, well, let's start off by making something bold. Let's say I want this description to be bold. All I have to do now is add the variable bold before that. To make sure the next line isn't still bold, we're then going to, say, set it back to normal after that. Otherwise, the next line and characters will be bold. I'm going to run that. If you look here, it's not very visible, but the partially cloudy is bold compared to that. You can underline it. You can strike through it. You can make it flash. Whatever you want. Again, check out my previous videos on all that. Let's go back in here now, and let's do something for the temperature. If I want the temperature, if it's hot, I can say, oh, let's make it red, and to make sure the next line isn't still red or any characters pass this, I'm going to set this back, the color back to default. Now I can run that, and you can see our temperature is red. Great. We can change that, though. We can add a little bit more. Again, this is just making it a little bit nicer. I'm going to copy and paste the save time here. What I'm doing here is I'm looking at the temperature, and the order of things in here is important. I'm saying, okay, look at temperature. Is it greater than 90 if it is, then set the variable color to red? If it's greater than 75, after it's checked the 90, so if it's greater than same five but less than 90, we're going to set the color to orange. If it's between 50 and 75, it's just going to be the regular, whatever your default color text is on your terminal, but if it's less than 50, we're going to go blue because it's cold. We're going to come down here, anything else, it'd be blank, which really you don't need to do. Well, I guess we do need to set the variable, otherwise you would get an error. We're going to say color. Now, depending on what the color is, it's orange because it's over 75. If it was over 90, it would be red. If it was below 75, it would just be in my case green. If it got below 50, then it would be blue. Those are some things you can do. You can go to my website and look at my notes. I will put a link in the description to the script on Pastebin, so you can just go copy and paste it. That's pretty much it. Things you can do with this, besides just having a command you can run to see the weather with some colors, is you can actually dump this. If I was to reload my shell and shrink this down, reload it again, it's not running right now. I used to have a script in here that would display the weather here, so any time I logged in my shell, it would display it. That being said, it's simple to do that if you're using bash, putting your bash RC file, if you're using ZShell, putting your ZRC file. But don't try to grab the weather real time like that. I will tell you, never try to do web requests in your RC file for your shell, because if it hangs at all, your shell won't load or will take a long time to load. What you want to do is create a cron job that every hour or every 15 minutes, the weather doesn't change that abruptly. So I would say once an hour or whatever you think is appropriate, dumps it into a text file that then your ZRC or bash RC file will dump out. That way it's saved. It's just text file. You're not hitting that server multiple times. You know, if you're loading the shell a lot and it's not going to hang. Anyway, that's just a thought there. In a coming up video, we are going to make a nice little gooey interface using the same concept with Godot. So go ahead and make sure you subscribe so you don't miss that. Check out the links in the description. And as always, I hope that you have a great day.