ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I thought it would be just a matter of looking that up on their extensive pages, but if they have that information visible it is buried in all the noise there. I suspect it is a matter of just finding the right query string and then parsing the resulting JSON.
So I would definitely contact them for a short example on what HTTP GET or POST query to use to fetch the data you are looking for in JSON format. https://weather.gc.ca/mainmenu/contact_us_e.html
I found a program on github that converts the https://weather.gc.ca/city/pages/on-118_metric_e.html page to JSON format. With this I can change the existing script and point it to the new file and get the correct weather.
Installation
npm install ec-weather
API
The module is called with a single options object.
const ecweather = require('ec-weather');
var options = {
lang: 'en',
city: 'on-118',
};
I found a program on github that converts the https://weather.gc.ca/city/pages/on-118_metric_e.html page to JSON format. With this I can change the existing script and point it to the new file and get the correct weather.
That program scrapes the HTML to attempt to produce JSON instead of using the weather service's own JSON. Somewhere the weather service has a link which you can query to get the JSON directly and thus avoid the brittleness which comes from trying to scrape. There's a feedback form at the bottom of the page you link to, if nothing else try contacting the weather service to let them know that their API is more or less hidden.
Edit: if you can get the API link from the weather service and post it here any number of us can provide an example of how to use the JSON it provides
Last edited by Turbocapitalist; 04-04-2023 at 10:15 PM.
@Turbocapitalist Thanks for the reply and I have sent a message to the weather.gc.ca site for information on a JSON lor API link.
@Treckk I tried your scripts and got these errors
I tried the first option and ran with sh and bash and got this error:
Code:
(END) % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
3 225k 3 7699 0 0 12417 0 0:00:18 --:--:-- 0:00:18 12417
curl: (23) Failed writing body (0 != 7699)
I tried the second option and get an error if I run as bash or sh:
Perhaps a little shell script to pull a certain item from a text file?
Code:
cat witem
Code:
#!/bin/bash
while read line
do
line=${line%$'\r'} # Remove a WinDOS CR
case $line in ( "$1:" )
read line2
line2=${line2%$'\r'}
echo "$line2"
break # Stop at first match
esac
done < weather-data.txt
Run as
Code:
bash witem Visibility
Or make it executable and run it like a program:
Code:
./witem Tendency
Last edited by MadeInGermany; 04-05-2023 at 03:16 AM.
That is exactly what I was looking for and it works great. It works for all the fields except Wind Chill because there is also a field called Wind. I tried to put "Wind Chill" in brackets and also tried Wind+Chill but Wind was still found.
If you have an answer to that you will be my champion.
You can search a keyword with spaces in the usual way:
Code:
./witem "Observed at"
Maybe the reason why it does not find "Wind chill" is that, unlike the other keywords, there is no colon after it.
And without the colon it will find "Wind chill" 3 times...
You can search a keyword with spaces in the usual way:
Code:
./witem "Observed at"
Maybe the reason why it does not find "Wind chill" is that, unlike the other keywords, there is no colon after it.
And without the colon it will find "Wind chill" 3 times...
I tried to run
Code:
./witem "Wind Chill"
again but it did not return anything ?
The first wind chill in the file at the moment is [38]Wind Chill:
-10
so I ran
Code:
./witem "[38]Wind Chill"
and it works so I hope that number does not change.
Well that didn't work the number goes up it is now 40 so I will have to leave wind chill off for now
Thanks for your help it has been a struggle for me but I have almost everything now. I would like to be able to capture the warnings but there doesn't seem to be anything to search for. Sometimes they are there other times they are not.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.