PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 23rd, 2012, 12:54 PM
mark014 mark014 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 mark014 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 33 sec
Reputation Power: 0
Question Weather icon extraction

I have on my website weather data from my personal weather station. Only thing it's missing its weather conditions. I would like to extract the weather condition icon from here
Code:
http://www.weather.com/weather/extended/PLXX0040?par=yahoo&site=www.yahoo.com&promo=extendedforecast&cm_ven=Yahoo&cm_cat=www.yahoo.com&cm_pla=forecastpage&cm_ite=CityPage
(Right Now window). Is there any way to do this?

Reply With Quote
  #2  
Old December 23rd, 2012, 12:57 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,907 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Month 15 h 2 m 22 sec
Reputation Power: 581
Yes.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old December 23rd, 2012, 01:49 PM
Rhytz's Avatar
Rhytz Rhytz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 102 Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 11 h 23 m 58 sec
Reputation Power: 50
You can do this with PHP Simple HTML DOM Parser

For example:

PHP Code:
include("simple_html_dom.php");
$html file_get_html('http://www.weather.com/weather/extended/PLXX0040?par=yahoo&site=www.yahoo.com&promo=extendedforecast&cm_ven=Yahoo&cm_cat=www.yahoo.com&cm_pla=forecastpage&cm_ite=CityPage');
echo 
$html->find('img[class=wx-weather-icon]')->src


Or with DOMXPath

Reply With Quote
  #4  
Old December 23rd, 2012, 02:38 PM
mark014 mark014 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 mark014 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 33 sec
Reputation Power: 0
Arrow

Thank you for answer. I tried PHP Simple HTML DOM Parser - downloaded that and uploaded on the server. Then I created new file and put into:
Code:
<?php include("/includes/simple_html_dom.php"); $html = file_get_html('http://www.weather.com/weather/extended/PLXX0040?par=yahoo&site=www.yahoo.com&promo=extendedforecast&cm_ven=Yahoo&cm_cat=www.yahoo.com&cm_pla=forecastpage&cm_ite=CityPage'); echo $html->find('img[class=wx-weather-icon]')->src;   ?>

I uploaded that file and insert the path to it in my browser and I have nothing - I mean blank website. What did I wrong?

Reply With Quote
  #5  
Old December 23rd, 2012, 03:03 PM
Rhytz's Avatar
Rhytz Rhytz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 102 Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 11 h 23 m 58 sec
Reputation Power: 50
I forgot to add a 0 in the $html->find.

Try it like this:

PHP Code:
 $weatherimage $html->find('img[class=wx-weather-icon]'0)->src;
echo 
"<img src='".$weatherimage."' alt='weather image' />"

Reply With Quote
  #6  
Old December 23rd, 2012, 03:39 PM
mark014 mark014 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 mark014 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 33 sec
Reputation Power: 0
Question

It's working. Thanks

By the way, I noticed that under the icon it's also a short text, eg. "Fog" (
Code:
http://www.weather.com/weather/extended/PLXX0040?par=yahoo&site=www.yahoo.com&promo=extendedforecast&cm_ven=Yahoo&cm_cat=www.yahoo.com&cm_pla=forecastpage&cm_ite=CityPage
).
It would be difficult to print it on my website but first translate it into my language? For instance, I would like to have not 'fog' but its meaning in my country 'mgla'. Thus it should be translated first...

Reply With Quote
  #7  
Old December 23rd, 2012, 04:13 PM
Rhytz's Avatar
Rhytz Rhytz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 102 Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 11 h 23 m 58 sec
Reputation Power: 50
Try this
PHP Code:
 $condition trim($html->find('li[class=wx-phrase]'0)->plaintext); //Extract the inner text from the <span class='wx-value' and trim off whitespace

switch ($condition) { //Switch between the different weather conditions
    
case "Fog":
        echo 
"mgla";
        break;
    case 
"Light Freezing Rain":
        echo 
"Your translation";
        break;
    case 
"Mostly Sunny":
        echo 
"Translation";
        break;
    default:
        echo 
$condition//You have not yet translated it so just show the English one



It should be noted however that if weather.com changes their site, this script might not work anymore.

Reply With Quote
  #8  
Old December 24th, 2012, 04:53 AM
mark014 mark014 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 mark014 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 33 sec
Reputation Power: 0
Thank you for your help one more time. Now I have all weather elements as I wanted. Unfortunately I wasn't able to do it alone. I hope weather.com won't change the script soon.

Reply With Quote
  #9  
Old December 24th, 2012, 05:29 AM
Rhytz's Avatar
Rhytz Rhytz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 102 Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 11 h 23 m 58 sec
Reputation Power: 50
Well, if they change it, it won't be so hard to change the script. I bet you can figure it out by the examples I just gave you

Reply With Quote
  #10  
Old January 5th, 2013, 10:52 AM
mark014 mark014 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 mark014 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 33 sec
Reputation Power: 0
icon's script generates error on my page?

The script worked fine for 2 weeks. Today something started to happen wrong. In the morning I noticed that my page is almost blank. Only weather banner and the text above the icon was visible. There wan't weather icon (snapshot ). When I deleted file with an icon the webpage opened correctly.

Thus, I know that the reason of an error is the icon's script. However I didn't change nothing recently. So I tried to do something with this and I changed code for the meteo station from weather.com for another station eg. PLXX1335 into PLXX0040. It helped and the icon was visible soon and the whole page too. Unfortunately, after a few hours the error occured again. I changed the code for station and it was the same - icon was visible as well as the whole page only for about 10 minutes. Now I have the icon's file deleted in order to have my site visible.

I don't know what could be the reason?

I attach the code for the script:
PHP Code:
<?php // pokaz pogodowe warunki //pobierz informacje include("simple_html_dom.php"); $html = file_get_html('http://www.weather.com/weather/extended/PLXX1335?par=yahoo&site=www.yahoo.com&promo=extendedforecast&cm_ven=Yahoo&cm_cat=www.yahoo.com&cm_pla=forecastpage&cm_ite=CityPage'); $weatherimage = $html->find('img[class=wx-weather-icon]', 0)->src; echo "<img src='".$weatherimage."' alt='weather image' />";   $condition = trim($html->find('li[class=wx-phrase]', 0)->plaintext); //Extract the inner text from the <span class='wx-value' and trim off whitespace echo"<br>";   switch ($condition) { //Switch between the different weather conditions     case "Fog":         echo "mgła";         break;     case "Light Freezing Rain":         echo "Słaby marznący deszcz";         break;     case "Light Freezing Rain / Fog":         echo "Słaby marznący deszcz/Mgła";         break;     case "Clear":         echo "bezchmurnie";         break;             case "Cloudy":         echo "pochmurno";         break;             case "Haze":         echo "zamglenia";         break;             case "Light Rain":         echo "słaby deszcz";         break;         case "Mostly Cloudy":         echo "<center>zachmurzenie duże</center>";         break;         case "Overcast":         echo "całkowite zachmurzenie";         break;         case "Partly Cloudy":         echo "częściowe zachmurzenie";         break;         case "Rain":         echo "deszcz";         break;         case "Rain Showers":         echo "opady deszczu";         break;         case "Showers":         echo "deszczyk";         break;         case "Light Rain Shower":         echo "lekki przelotny deszcz";         break;         case "Thunderstorm":         echo "burza";         break;         case "Mostly Sunny":         echo "przeważnie słonecznie";         break;         case "Partly Sunny":         echo "częściowo słonecznie";         break;         case "Mostly Sunny":         echo "słonecznie";         break;         case "Sunny":         echo "słonecznie";         break;         case "Fair":         echo "pogodnie";         break;         case "Scattered Showers":         echo "przelotny deszcz";         break;         case "Snow":         echo "śnieg";         break;         case "Light Snow":         echo "słabe opady śniegu";         break;         case "Light Rain / Windy":         echo "słaby deszcz / wietrznie";         break;     default:         echo $condition; //You have not yet translated it so just show the English one }   ?>


The script responsible for printing the icon on my page (in PHP - here ):
Code:
<div class='ikona'>"; include('includes/icon.php'); echo"</div>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Weather icon extraction

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap