Author Topic: "Sunrise Tomorrow" tag in WL template?  (Read 3965 times)

0 Members and 1 Guest are viewing this topic.

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
"Sunrise Tomorrow" tag in WL template?
« on: December 29, 2010, 01:24:21 PM »
 :?: Showing my n00biness here...

WL has so far been simple enough to use.  I'm making all sorts of messes with the templates to get it to make my personal weatherpage look the way I want.

The first thing I had to do was kill the davisticker java applet.  When viewing my webpage with it running, the PC clock starts running at 1.5x speed!  I verified this on my winxp-sp3 box and wife's win7 laptop.  Both running IE8 browser.  Not such a big deal.  It's nice to have little tools like that to play with.

What I would REALLY like to do is put tomorrow's sunrise on my webpage.  I found the tags for sunrise and sunset,
Code: [Select]
<!--sunriseTime-->
<!--sunsetTime-->
and they work just fine.  But they are only for today.  The sun is already up!  I care more about tomorrow's sunrise.

Ideally, I would like to have something like...
Sunrise today 07:30  Sunset tonight 16:30
Sunrise tomorrow 07:25  Sunset tomorrow 16:35


Is there a way to get that info to extract from a sunrise/sunset report and upload with the schedule template and/or images?


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9297
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #1 on: December 29, 2010, 01:52:08 PM »
AFAIK, WeatherLink doesn't provide tomorrow's sunrise/sunset date/time.. only todays.

The davisticker applet is a long-known CPU hog, and most folks have taken it off their site.  There are multiple JavaScript scrollers that can do the same thing without the enormous overhead of Java running in your browser.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #2 on: December 29, 2010, 02:19:32 PM »
If and when you switch from straight HTML to PHP, there are sunrise and sunset commands built into PHP, as well as a moonrise/moonset script and moon phase script floating around.

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #3 on: December 29, 2010, 02:40:34 PM »
If and when you switch from straight HTML to PHP, there are sunrise and sunset commands built into PHP, as well as a moonrise/moonset script and moon phase script floating around.
"IF?"  I'm not afraid of php...   "WHEN?"  I've got some time right now!

Thinking as I go...  Are you speaking of some website to poll the value (based on lat/long) and post to my page via rss, or the numbers crunched within the php script itself?  It wouldn't be my first franken-page.  Can you point me toward a starting point?  I can't hold it against WL for not having the advanced features.  If it wasn't so simple (took about 30 minutes to have my first weather-page online) I wouldn''t be so excited to keep going.

Thanks!


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #4 on: December 29, 2010, 02:58:14 PM »
Crunched in the script itself...

In a PHP script, you feed the date_sunrise and date_sunset commands the lat and lon of your station, and the date and they return the appropriate time. Oh, and you need to use the zenith value, too, which determines which twilight is considered the rise or set time, or whether it's the time the sun actually peeps over or under the horizon.

http://php.net/manual/en/function.date-sunrise.php
http://www.php.net/manual/en/function.date-sunset.php

Well, the first thing to do is verify that your weather web server is capable of running PHP scripts. If not, switch to one that can, on install PHP, or whatever it takes to get it going.

Then, start playing... :)

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #5 on: December 29, 2010, 03:17:37 PM »
In a PHP script, you feed the date_sunrise and date_sunset commands the lat and lon of your station, and the date and they return the appropriate time. Oh, and you need to use the zenith value, too, which determines which twilight is considered the rise or set time, or whether it's the time the sun actually peeps over or under the horizon.
I can do that!  There are so many php commands I never knew about, mainly because I have only bothered to learn enough to hack/customize/tweak existing scripts.  For now, I think I will use 90 for azimuth, and add 24hrs to the query-string for tomorrow's data.

Thanks!  Good thing work is slow today...


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline dalecoy

  • Forecaster
  • *****
  • Posts: 6447
    • Lee's Summit, MO
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #6 on: December 29, 2010, 03:52:36 PM »
Notes:

1.  Presumably, you'll have to also either display both sets of sunrise/sunset (today and tomorrow) - or figure out a way to make it clear that "sunset is for today but sunrise is for tomorrow because..."

2.  Sunrise and sunset aren't actually weather things.  But you knew that.

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #7 on: December 29, 2010, 04:11:58 PM »
@dalecoy...  I have an idea...  For todays date_sunrise I'll make a variable using the $timestamp function and tag the result appropriately.  For tomorrow's date_sunrise I'll make a variable using the $timestamp function plus the int equivalent of 24-hours, and tag the result appropriately.  Not sure exactly how I'm going to do that, but I'll post it when I do.  (Unless someone has already figured it out and wants to share?)

@dalecoy again...  Yeah, sunrise/sunset aren't wx, but it is always on the weather page of the paper, the local news, and even wunderground.  Neither is moon phase, but it's something I'm used to seeing my whole life associated with the weather report, so I figured, why not?

I wish I had the old "donkey tail weather forecaster" from grandpa's porch, for nostalgia's sake.  They must still exist in some back-road gift shop somewhere.


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline dalecoy

  • Forecaster
  • *****
  • Posts: 6447
    • Lee's Summit, MO
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #8 on: December 29, 2010, 04:22:47 PM »
In many places, the times of high and low tide are also on the weather page.

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Re: "Sunrise Tomorrow" tag in WL template?
« Reply #9 on: December 30, 2010, 01:02:14 AM »
In many places, the times of high and low tide are also on the weather page.

And if you wanna "roll yer own", that means running xtide on your server, and a cron job for whatever locations/update periods you want tide graphs/tables.

(Been there, done that, got the T-shirt, for SLOweather and several other weather sites. ;) )

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Ah figgrd it out!
« Reply #10 on: December 31, 2010, 11:05:37 AM »
It really only took a few minutes, once I knew the commands.  Tomorrow is simply "+1 day" in the function.  It took all day to move my website to a hosting server that offered php5 so I could get it to work.

[edit] I suppose I could have added 86400 seconds to the original time() result as I originally thought, but I like shortcuts like the strtotime (string-to-time) function that lets me speak engrish to the computer.[/edit]

Code: [Select]
<?php

$lat 
47.3;
$long = -122.1;
$zenith 90+50/60;
$offset = -8;

echo 
"<p>Sunrise Today: ".date_sunrise(strtotime(), SUNFUNCS_RET_STRING$lat$long$zenith$offset);
echo 
"<br>Sunset Tonight: ".date_sunset(strtotime(), SUNFUNCS_RET_STRING$lat$long$zenith$offset);

echo 
"<p><br>Sunrise Tomorrow: ".date_sunrise(strtotime("+1 day"), SUNFUNCS_RET_STRING$lat$long$zenith$offset);
echo 
"<br>Sunset Tomorrow: ".date_sunset(strtotime("+1 day"), SUNFUNCS_RET_STRING$lat$long$zenith$offset);

?>

Result below...

Sunrise Today: 07:53
Sunset Tonight: 16:30

Sunrise Tomorrow: 07:53
Sunset Tomorrow: 16:31


Thanks for the help.  Since everything is frozen right now, watching the tickers is kinda boring.  A little coding passes the time.
« Last Edit: December 31, 2010, 01:23:13 PM by xykotik »


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
FULL CIRCLE - Sunrise Tomorrow in WeatherLink template
« Reply #11 on: January 01, 2011, 12:12:38 AM »
 :grin: I've had fun this New-Year's-Eve!  In the tradition of support forums, I would like to share my final solution, in case someone finds this post from a search engine (which I didn't).

My original question was... "How do I get 'sunrise tomorrow' into the WL templates?"  The answer was to go beyond <!--WeatherTags--> and basic HTML and use existing PHP functions for that purpose.  Once I got that going, I tweaked it to format the output in a way my family might accept (non 24hr).

Here is the code that I added to my WeatherLink .htx template, to display sunrise/sunset for tomorrow...  Some things to keep in mind are...
  • Requires a server running PHP5 or the DatePHP4 module
  • Place the code below inside your OWN <table> tags in a .php document (rename your .html file if necessary)
  • Cells and fonts match Davis WeatherLink DEFAULT templates.
  • If using WeatherLink, set to convert .htx templates to .php extensions.
  • Don't forget to set your variables!

Code: [Select]
<?php
/* ------------------------------------------------------------------ */
/* -------------- BEGIN SUNRISE/SUNSET BY 'XYKOTIK' ----------------- */
/* --- MODIFY THE NEXT FIVE VARIABLES ACCORDING TO YOUR LOCATION ---- */
/* -- SEE 'PHP.NET/MANUAL/EN/TIMEZONES.PHP' TO FIND YOUR TZ STRING -- */
/* ------------------------------------------------------------------ */

$latitude 46.3;
$longitude = -121.1;
$zenith 90+50/60;
$gmt_offset = -8;
date_default_timezone_set('America/Los_Angeles');

$sunrise_today strftime("%l:%M%P"date_sunrise(strtotime(), SUNFUNCS_RET_TIMESTAMP$latitude$longitude$zenith$gmt_offset));
$sunset_today strftime("%l:%M%P"date_sunset(strtotime(), SUNFUNCS_RET_TIMESTAMP$latitude$longitude$zenith$gmt_offset));
$sunrise_tomorrow strftime("%l:%M%P"date_sunrise(strtotime("+1 day"), SUNFUNCS_RET_TIMESTAMP$latitude$longitude$zenith$gmt_offset));
$sunset_tomorrow strftime("%l:%M%P"date_sunset(strtotime("+1 day"), SUNFUNCS_RET_TIMESTAMP$latitude$longitude$zenith$gmt_offset));

echo 
"<tr><td  bordercolor=\"#000000\" style=\"border: thin solid rgb(0,0,0)\" >";
echo 
"<font face=\"verdana, Arial, Helvetica\"><strong><font color=Brown><small>";
echo 
"Sunrise / Sunset<br>Today<br></small></font></strong></font></td>";
echo 
"<td bordercolor=\"#000000\" style=\"border: thin solid rgb(0,0,0)\" >";
echo 
"<font face=\"verdana, Arial, Helvetica\"><strong><font color=\"#3366FF\"><small>";

echo 
$sunrise_today ." / "$sunset_today;

echo 
"<br></small></font></strong></font></td></tr>";

echo 
"<tr><td  bordercolor=\"#000000\" style=\"border: thin solid rgb(0,0,0)\" >";
echo 
"<font face=\"verdana, Arial, Helvetica\"><strong><font color=Brown><small>";
echo 
"Sunrise / Sunset<br>Tomorrow<br></small></font></strong></font></td>";
echo 
"<td bordercolor=\"#000000\" style=\"border: thin solid rgb(0,0,0)\" >";
echo 
"<font face=\"verdana, Arial, Helvetica\"><strong><font color=\"#3366FF\"><small>";

echo 
$sunrise_tomorrow ." / "$sunset_tomorrow;

echo 
"<br></small></font></strong></font></td></tr>";

/* ------------------------------------------------------------------ */
/* -------------- END SUNRISE/SUNSET BY 'XYKOTIK' ------------------- */
/* ---------- THANKS TO THE FINE FOLKS AT WXFORUM.NET --------------- */
/* ------------------------------------------------------------------ */
?>


It looks something like THIS...


I hope someone can find this useful.  I don't believe I will be using WL forever, but I have to say, if the interface wasn't so slick and easy (even if limited) I don't know how many amatuer wx-watchers would want to keep on keepin' on. 

Now I have a few months to figure out what I am going to do about DST  #-o

 UU HAPPY NEW YEAR!!!  UU


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.