Weather

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Weather

Post by Quinton B. » Fri Jun 15, 2018 10:12 pm

I'm trying to use the browser widget to go to a specific point on the page after launching the URL, or crop the view to that specific frame. For example, image 1 contains what I see in the browser, however, image 2 shows what I only want to see. How would I go about only seeing image 2, or does someone have a weather widget that I can use?
Attachments
Capture1.PNG
Capture2.PNG
Capture2.PNG (3.07 KiB) Viewed 8239 times

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: Weather

Post by Volkmar » Sun Jun 17, 2018 5:16 pm

I use https://weather.com - the ten day overview.
You can try maybe the weather for a french city:
https://weather.com/de-DE/wetter/10tage ... c0d4f1dc11

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Weather

Post by Newbie4 » Sun Jun 17, 2018 7:08 pm

If you just want the temperature, you can use an api to get that data from the weather site. Then you can format and show it in text or use your own graphics. It gives you more control and allows you to customize your screen. You can also get other related data, like the wind speed, the sky conditions, etc. and add it to your program

There is a short intro to creating a weather app at https://sites.google.com/a/pgcps.org/li ... me/mashups. You can use that code in your own program.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Weather

Post by Quinton B. » Wed Jun 20, 2018 9:00 am

Volkmar wrote:
Sun Jun 17, 2018 5:16 pm
I use https://weather.com - the ten day overview.
You can try maybe the weather for a french city:
https://weather.com/de-DE/wetter/10tage ... c0d4f1dc11
How can you retrieve their sky condition image, temperature and time?

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Weather

Post by Quinton B. » Wed Jun 20, 2018 9:03 am

Thanks.
I was able to retrieve the data:

#The CSV format is in following way:-
#First row contains the current weather condition. If for any reason we do not have current condition it will have 'Not Available'.
#The current weather condition data is laid in the following way:-
#observation_time,temp_C,temp_F,weatherCode,weatherIconUrl,weatherDesc,windspeedMiles,windspeedKmph,winddirDegree,winddir16Point,precipMM,humidity,visibilityKm,pressureMB,cloudcover
#
#The day information is available in following format:-
#date,maxtempC,maxtempF,mintempC,mintempF,sunrise,sunset,moonrise,moonset,moon_phase,moon_illumination
#
#Hourly information follows below the day in the following way:-
#date,time,tempC,tempF,windspeedMiles,windspeedKmph,winddirdegree,winddir16point,weatherCode,weatherIconUrl,weatherDesc,precipMM,humidity,visibilityKm,pressureMB,cloudcover,HeatIndexC,HeatIndexF,DewPointC,DewPointF,WindChillC,WindChillF,WindGustMiles,WindGustKmph,FeelsLikeC,FeelsLikeF,chanceofrain,chanceofremdry,chanceofwindy,chanceofovercast,chanceofsunshine,chanceoffrost,chanceofhightemp,chanceoffog,chanceofsnow,chanceofthunder
#
07:57 AM,12,54,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,4,7,130,SE,7.0,100,16,1023,50
2018-06-20,21,70,10,50,05:31 AM,08:30 PM,01:17 PM,01:16 AM,First Quarter,34
2018-06-20,0,12,54,3,5,357,N,356,http://cdn.worldweatheronline.net/image ... g,Moderate or heavy rain shower,7.0,96,16,1016,86,13,55,12,54,13,55,7,11,13,55,96,0,0,90,0,0,0,0,0,90
2018-06-20,300,11,52,5,8,273,W,299,http://cdn.worldweatheronline.net/image ... g,Moderate rain at times,0.7,95,19,1016,77,12,54,11,52,12,54,9,15,12,54,66,0,0,87,0,0,0,0,0,7
2018-06-20,600,10,50,4,6,278,W,299,http://cdn.worldweatheronline.net/image ... g,Moderate rain at times,0.7,94,18,1016,74,11,52,11,52,11,52,8,13,11,52,68,0,0,94,0,0,0,0,0,0
2018-06-20,900,15,59,5,8,323,NW,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,0.0,77,20,1016,5,16,61,12,54,16,61,7,12,16,61,0,89,0,44,77,0,0,0,0,0
2018-06-20,1200,19,67,10,15,30,NNE,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,0.0,47,20,1015,8,20,68,9,48,20,68,12,19,20,68,0,83,0,43,80,0,0,0,0,0
2018-06-20,1500,21,70,10,16,19,NNE,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,0.0,46,20,1013,7,22,72,9,48,22,72,12,19,22,72,0,89,0,42,77,0,16,0,0,0
2018-06-20,1800,20,68,11,18,13,NNE,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,0.0,40,20,1014,12,21,70,7,45,21,70,18,28,21,70,0,80,0,31,79,0,0,0,0,0
2018-06-20,2100,16,61,9,14,11,N,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,0.0,67,19,1014,12,17,63,11,52,17,63,10,17,17,63,0,84,0,35,86,0,0,0,0,0


I only need the time, max temp *F, and the sky condition .png
How would I go about retrieving only those?

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Weather

Post by Newbie4 » Wed Jun 20, 2018 3:25 pm

You can pick off the items that you want from the data. They are separated by commas

Looking at your data:
07:57 AM,12,54,116,http://cdn.worldweatheronline.net/image ... png,Partly cloudy,4,7,130,SE,7.0,100,16,1023,50
2018-06-20,21,70,10,50,05:31 AM,08:30 PM,01:17 PM,01:16 AM,First Quarter,34
2018-06-20,0,12,54,3,5,357,N,356,http://cdn.worldweatheronline.net/image ... g,Moderate or heavy rain shower,7.0,96,16,1016,86,13,55,12,54,13,55,7,11,13,55,96,0,0,90,0,0,0,0,0,90
2018-06-20,300,11,52,5,8,273,W,299,http://cdn.worldweatheronline.net/image ... g,Moderate rain at times,0.7,95,19,1016,77,12,54,11,52,12,54,9,15,12,54,66,0,0,87,0,0,0,0,0,7
...
and it's layout:
#The CSV format is in following way:-
#First row contains the current weather condition. If for any reason we do not have current condition it will have 'Not Available'.
#The current weather condition data is laid in the following way:-
#observation_time,temp_C,temp_F,weatherCode,weatherIconUrl,weatherDesc,windspeedMiles,windspeedKmph,winddirDegree,winddir16Point,precipMM,humidity,visibilityKm,pressureMB,cloudcover
#
#The day information is available in following format:-
#date,maxtempC,maxtempF,mintempC,mintempF,sunrise,sunset,moonrise,moonset,moon_phase,moon_illumination
#
#Hourly information follows below the day in the following way:-
#date,time,tempC,tempF,windspeedMiles,windspeedKmph,winddirdegree,winddir16point,weatherCode,weatherIconUrl,weatherDesc,precipMM,humidity,visibilityKm,pressureMB,cloudcover,HeatIndexC,HeatIndexF,DewPointC,DewPointF,WindChillC,WindChillF,WindGustMiles,WindGustKmph,FeelsLikeC,FeelsLikeF,chanceofrain,chanceofremdry,chanceofwindy,chanceofovercast,chanceofsunshine,chanceoffrost,chanceofhightemp,chanceoffog,chanceofsnow,chanceofthunder
#
You can get the time (item #1) and the sky condition (item #5) from the first line which has the current weather conditions
You can get the max tempF (item #3) from the next line which has the day information.

Assuming you retrieved the weather data into a variable "myData", the code is straight-forward:

Code: Select all

put item 2 of line 1 of myData into mytime
put item 5 of line 1 of myData into mySky
put item 3 of line 2 of myData into myMaxTemp
The line numbers may have to be adjusted if the descriptions are in your data
e.g.

Code: Select all

put item 2 of line 12 of myData into mytime
put item 5 of line 12 of myData into mySky
put item 3 of line 13 of myData into myMaxTemp
if you have fields defined on your card, you can move the data there:

Code: Select all

put item 2 of line 12 of myData into field "mytime"
put item 5 of line 12 of myData into graphic "mySky"
put item 3 of line 13 of myData into field "myMaxTemp"
(You may have to play around with the png to get it to look right. I did not test that code out.)

You should also check for "not Available" and handle that condition by substituting defaults or a message.

Hope this is what you are looking for...
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Weather

Post by Quinton B. » Thu Jun 21, 2018 7:07 am

That was a trial API. I have found an actual free one "openweathermap.org", weather channel doesn't give out free API anymore. However I'm able to extract this from the new API with the help of your "put item x of line x of myData into tTemp", but this displays exactly like it is bellow.
I have tried some ways of only extracting the numeric value without success.
The temperature is in Kelvin, so I made a quick calculation to change it to Fahrenheit.

"temp_max":292.15

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Weather

Post by Newbie4 » Thu Jun 21, 2018 1:36 pm

That is great. You are making progress!

There are at least 2 ways that you can pull off the temperature part of that item.

1. Treat it as another list but instead of the items being separated with commas (,), it uses colons (:). So you change the item-delimiter from a comma to a colon and pull off the second item. Then you change it back.

e.g.
put item 3 of line 12 of myData into x
set the itemdelimiter to ":"
put item 2 of line 1 of x into myMaxTemp
set the itemdelimiter to ","
2. Assuming the descriptor "temp_max": never changes, jump over it. Start with character #12 and use the rest of it.

e.g.
put chars 12 to 16 of item 3 of line 12 of myData into myMaxTemp
Take a break and look up itemdelimiter in LiveCode and look at the BYU lessons on handling text. Handling text is one of the strengths of LiveCode

You can look for other weather APIs. Many of them offer a free account but with a limit of how many times you can use it. (e.g. 1,000 times a month). It you are going to sell your app and have many people using your app to hit their weather site, it is only fair that you pay them for the server resources that your app will be using. In that case, pay for a monthly account of their API

You are making good progress. Keep reading the documentation and learning how to do different things in LiveCode. Look at every problem as an opportunity to learn more about the language. It will pay off and more than likely, you will need it again in the future.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Weather

Post by Quinton B. » Thu Jun 21, 2018 9:03 pm

Thanks, I shall implement that tonight. As of right now the app is free, but I have yet to decide if I want to change for it. But I do plan on paying for their app service once it starts. I tried using noaa,s API. But it wasn't well documented as in special in url exemplifiers. As noaa data would be free. But it truly complex. Thank you guys for your help so far.

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Weather

Post by Quinton B. » Fri Jun 22, 2018 7:47 am

Thanks, I was able to complete that objective with a couple more lines of code.
The next objective is to crop the browser widget.
Currently, I can see this (Capture3.PNG)
But I would like to see only this (Capture4.PNG)
I have tried placing something over it, but it will just be directed behind the browser widget, even with the code on a loop to keep placing the object over the top portion it will be directed behind the widget.
Is their a way to customize the HTML being displayed?
Attachments
Capture4.PNG
Capture3.PNG

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Weather

Post by jacque » Fri Jun 22, 2018 6:40 pm

A browser will always be on top and can't be cropped, it will always display the full content of the HTML it contains. The solution is to edit out the parts of the HTML you don't want.

The images you posted aren't weather related, so I'm not sure if that is content you want to preserve or just an example. If you only want to show the current weather conditions you don't really need a browser. You can use a field for the text and an image object for the icon.

Back 100 years ago when I wrote my own weather stack, that's what I did. I also included the current radar map which I think was downloaded as an animated gif if I remember right. It was a long time ago though, things may have changed.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Weather

Post by Quinton B. » Sat Jun 23, 2018 5:02 am

I appreciate the help. But no this is not for the weather portion of the app.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”