Author Topic: Change Background Image depending upon Wx conditions? - SOLVED  (Read 4053 times)

0 Members and 1 Guest are viewing this topic.

Offline Phlerb

  • Expert Weather Dabbler
  • Member
  • *
  • Posts: 18
    • Old Pump Road Wx
Change Background Image depending upon Wx conditions? - SOLVED
« on: January 03, 2015, 09:40:44 AM »
Good Day!

I continue to push towards a more unique web site, and I was wondering if anyone had a script that would change the background of the Saratoga Templates css depending upon the reported weather conditions?

Ultimately I would have about 14 different images to choose from. 7 night time ones and 7 day time for:
Sunny/Clear
Rainy
Windy
Snowy
Cloudy
Thunderstorms
Foggy

This page seems to be a start, but it uses yahoo weather and is about 5 years old and I bet it no longer works that way, and we already gather that information to display on the front page in the summary temperature section.

http://css-tricks.com/using-weather-data-to-change-your-websites-apperance-through-php-and-css/

Any hints or clues on how to do this would be super!

Thanks
Phil
« Last Edit: January 07, 2015, 02:24:15 PM by Phlerb »

Offline txweather.org

  • Forecaster
  • *****
  • Posts: 1597
    • Texas Weather
Re: Change Background Image depending upon Wx conditions?
« Reply #1 on: January 03, 2015, 10:27:16 AM »
Get in contact with Win on this forum. He is the creator of the Leuven template and it does exactly what you are trying to archive.

----
Davis Vantage Pro2 Plus +FARS|Meteobridge Nano SD|Meteohub|Meteobridge MR-3020|WU KTXSPRIN75/PWS JRARGWX75/CWOP EW2972/WBB TXWDVUE75/Blitzortung ID: 1142|AWEKAS: 12095
Donations are welcome: https://paypal.me/ffuentesb

Offline Ian.

  • Forecaster
  • *****
  • Posts: 460
    • Chatteris Weather
Re: Change Background Image depending upon Wx conditions?
« Reply #2 on: January 03, 2015, 12:45:42 PM »
Phil,

Check out http://www.clevedonweather.co.uk/station/banner.php it changes the header so might be of use.

Ian
« Last Edit: January 03, 2015, 12:47:53 PM by redpis »
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline Phlerb

  • Expert Weather Dabbler
  • Member
  • *
  • Posts: 18
    • Old Pump Road Wx
Re: Change Background Image depending upon Wx conditions?
« Reply #3 on: January 03, 2015, 01:53:34 PM »
Thanks redpis.

I looked at the code, and it is using clientraw, which I think is a Weather Display file, and I use cumulus. He also was using % solar, which I do not have as I have a Davis Vue, and no Solar Rad measurement..

xcom: Thank you! This is closer to what I was looking at. I did not determine the code, but I have reached out to the Leuven team via their website and hope to hear back.

Offline kocher

  • Senior Member
  • **
  • Posts: 85
    • San Sebastian (Spain)
Re: Change Background Image depending upon Wx conditions?
« Reply #4 on: January 04, 2015, 01:55:12 PM »
I know another way to create a dynamic banner.
On my site, I use it for some time and it works very well.
Detects day, night, fog, rain, snow, frost etc ....
You do not need a solar sensor.
Depending on weather conditions, automatically changes the image of our banner ..

     http://kocher.es/index.php

The idea came from here (it's a script thought, in principle, to stations Davis Vantage ):

    http://www.meteoelche.com/download.php

You have to download the archive metoActual.rar

It contains two very easy to understand PDF files (one with images).

This program gives us 3 icons:

1) Current Weather (curweather.php)

2) Moon Phase (fasmoon.php)

3) Trend of time (preweat.php)

These icons can see on our website.

The only thing left is to replace (equivalently) the images in the folder i by images of our banner.
I duplicate the folder i (original icons) with another if (our images)

    http://kocher.es/curweat.php
    http://kocher.es/curbannerweat.php
« Last Edit: October 13, 2018, 05:30:02 PM by kocher »
Windows 7 Pr
Davis Vantage Pro Plus f.a.
WeatherLink 6.0.2
Meteotemplate 15.0 Black Currant
CumulusMX
GraphWeather Version 3.0.15


Offline Phlerb

  • Expert Weather Dabbler
  • Member
  • *
  • Posts: 18
    • Old Pump Road Wx
Re: Change Background Image depending upon Wx conditions?
« Reply #5 on: January 04, 2015, 02:17:34 PM »
Thank you Kocher.

Unfortunately I don't know Spanish, and I am using Cumulus and not weatherlink. And as far as I can tell now you cannot use both at the same time.

Wim did reply to me, but essentially the Saratoga Templates and his are completely different and there is no easy way to convert his solution to the Saratoga Template.

:(

Thanks for taking the time everyone!

I have a feeling it may need to use the WeatherUnderground API to get the needed info, and then a script to pass to the various css files which image to use.

Offline kocher

  • Senior Member
  • **
  • Posts: 85
    • San Sebastian (Spain)
Re: Change Background Image depending upon Wx conditions?
« Reply #6 on: January 04, 2015, 02:27:43 PM »
What a shame!, Because it works very well.

Greetings from San Sebastián
Windows 7 Pr
Davis Vantage Pro Plus f.a.
WeatherLink 6.0.2
Meteotemplate 15.0 Black Currant
CumulusMX
GraphWeather Version 3.0.15


Offline Phlerb

  • Expert Weather Dabbler
  • Member
  • *
  • Posts: 18
    • Old Pump Road Wx
Re: Change Background Image depending upon Wx conditions?
« Reply #7 on: January 04, 2015, 02:46:22 PM »
So, Looking more into it, the API call is this for php  (http://www.wunderground.com/weather/api/d/docs?d=data/index)

<?php $json_string = file_get_contents("YOUR API"); ?>

(I changed the API)

And in this there is a "weather" return that has the current conditions...

So, it would seem that you would just need to have the css page query the API and then see what the conditions are, and then map the conditions to an image...

So, I made a quick php page, and added this code:

Code: [Select]
<?php $json_string file_get_contents("YOUR API"); 
$parsed_json json_decode($json_string); 
$weather $parsed_json->{'current_observation'}->{'weather'}; 
echo 
"${weather}\n"?>

And it returns right now

Mostly Cloudy

You can see it here

http://www.deadcowz.com/wuapicall.php

So, now, how to use this data to select the correct image....

Getting closer...
« Last Edit: April 26, 2016, 06:09:09 PM by ALITTLEweird1 »

Offline Dr Obbins

  • Forecaster
  • *****
  • Posts: 1152
Re: Change Background Image depending upon Wx conditions?
« Reply #8 on: January 04, 2015, 02:53:41 PM »
While it doesn't change my background, I use the cloudbase script to change my banner. Just saved a copy in a new folder cloudbase2. Really not much to do except make the new jpg pics and change the x,y coordinates on a few items. This keeps the banner current with the weather conditions.


It looks like you banner needs changing anyway - it is showing a school bus out in the snow! :roll: LOL:lol:
« Last Edit: January 04, 2015, 03:13:05 PM by Dr Obbins »

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2297
    • CNYWeather
Re: Change Background Image depending upon Wx conditions?
« Reply #9 on: January 04, 2015, 04:23:51 PM »
While it doesn't change my background, I use the cloudbase script to change my banner. Just saved a copy in a new folder cloudbase2. Really not much to do except make the new jpg pics and change the x,y coordinates on a few items. This keeps the banner current with the weather conditions.


It looks like you banner needs changing anyway - it is showing a school bus out in the snow! :roll: LOL:lol:

Where did you change the script to make the image larger?
Tony




Offline Phlerb

  • Expert Weather Dabbler
  • Member
  • *
  • Posts: 18
    • Old Pump Road Wx
Re: Change Background Image depending upon Wx conditions?
« Reply #10 on: January 04, 2015, 06:03:31 PM »
I ended up using a php job to check the wunderground, then some if / elseif to copy a file to be named current.jpg every 20 minutes with a cron job, and then updated the css files to point to /images/current/current.jpg... so every 20 minutes current.jpg will reflect the weather as reported by weather underground.

Next is to add logic for day versus night, but that is for after dinner!
(API changed)

Code: [Select]
<?php $json_string file_get_contents("YOUR API"); 
$parsed_json json_decode($json_string); 
$weather $parsed_json->{'current_observation'}->{'weather'}; 

if (
in_array($weather, array('Mostly Cloudy''Cloudy''Partly Cloudy''Overcast')))
{
copy("/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/cloudy.jpg""/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/current.jpg");
}

elseif (
in_array($weather, array('Sunny''fair')))
{
copy("/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/sunny.jpg""/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/current.jpg");
}
elseif (
in_array($weather, array('thundershowers''isolated thunderstorms''scattered thunderstorms''isolated thundershowers')))
{
copy("/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/thunderstorm.jpg""/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/current.jpg");
}
elseif (
in_array($weather, array('showers''rain''mixed rain and hail''scattered showers''mixed rain and snow''freezing rain')))
{
copy("/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/rainy.jpg""/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/current.jpg");
}
elseif (
in_array($weather, array('snow''heavy snow''snow flurries''light snow showers''blowing snow')))
{
copy("/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/snow.jpg""/kunden/homepages/17/d554858752/htdocs/DEADCOWZdomainroot/images/current/current.jpg");
}
?>

« Last Edit: April 26, 2016, 06:09:44 PM by ALITTLEweird1 »

Offline Dr Obbins

  • Forecaster
  • *****
  • Posts: 1152
Re: Change Background Image depending upon Wx conditions?
« Reply #11 on: January 04, 2015, 07:59:24 PM »
Where did you change the script to make the image larger?
The size is controlled by the size of your pictures. There is no setting for the pic size, however this is where the x,y coordinates come into play for the location of the sun/moon/windsock. The banner I used is a bunch of the cloudbase pics merged together. Attached are some of the pics needed and the PHP file. The file size was too big for all of them zipped, but if you PM you email I can send them to you if your are interested.

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Change Background Image depending upon Wx conditions? - SOLVED
« Reply #12 on: April 26, 2016, 05:59:14 PM »
OK first Im not sure it is a good idea to use his API key, he shoulnd't have posted it here at all.

And with regards to the link, try changing http to https