On 09/05/2013 04:14 AM, Levent SARI wrote:
Merhabalar,
Ufak bir denizcilik firmasında çalışan arkadaşımın ricasi üzerineher
gün düzenli çıktı alıp çalışma raporlarına eklemeleri gereken günlük
hava tahminlerini çıktı işini dahada kolaylaştırmak adına kendilerine
küçük bir php scripti(bknz:1) yazdım.
Keza kullandıkları sayfanın orijinali burası
olup(http://www.mgm.gov.tr/tahmin/il-ve-ilceler.aspx?m=ISTANBUL#sfB),
sayfa içerisinde çıktısı almaları gereken kısım ise sadece
burası(http://www.fuzzyscript.com/meteoroloji/istanbul.php).
Yazdığım script şuan tamamen işlerini görüyor. Fakat tek sorunumuz
sizinde gördüğünüz gibi hava olaylarının(HADİSE) olduğu kısımda
görüntüleyemediğimiz image dosyaları.
Meteorolojinin kendi sayfasında image dosyalarının url kısımları şu
şekilde(<img id="cp_sayfa_imgHadise1"
src="../FILES/imgIcon/99/e_36x36t_png/-25.png" alt="PARÇALI BULUTLU">)
Haliyle yazdığım php scriptinin sayfasında bu image dosyaları ne yazık
ki görüntülenemiyor.
Ve bu görsellerinde çıkması oldukca önemli.
Bu durumu düzeltmek adınane önere bilirsiniz?
Kolaylıklar Levent "SARI"
--------------------------------------------------------
1-)
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Hava Tahmin</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
</head>
<body>
<?php
function cekecek($site)
{
if(function_exists('curl_exec')) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $site);
curl_setopt($ch,CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686;
tr-TR; rv:1.9.0.3) Gecko/2008092818 Pardus/2008 Firefox/4.0.0');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($oturum, CURLOPT_SSL_VERIFYPEER, false);
$return = curl_exec($ch);
curl_exec($ch);
return $return;
}
else{
return file_get_contents($site);
}
}
$source =
cekecek('http://www.mgm.gov.tr/tahmin/il-ve-ilceler.aspx?m=BESIKTAS#sfB');
preg_match_all('#<h1 id="sfB"
style="clear:both;">(.*?)<\/h1>#si',$source,$pars);
foreach($pars[1] as $elemen)
echo '<center>' .$elemen;
preg_match_all('#<div id="cp_sayfa_tahmin5gunluk">(.*?)<\/div>#si',
$source,$parse);
foreach($parse[1] as $element)
echo $element;
?>
</body>
</html>
Bir uygulamanin parcasi olan bir koddan ayikladim.
<?php
class weather {
public $il;
public $info;
public $current;
public $forecast_list;
public $e;
private $get_data;
public function __construct($il='ISTANBUL') {
$this->il = $il;
}
public function get_url() {
if (!($this->get_data = iconv('ISO-8859-9',
'UTF-8',file_get_contents('http://www.mgm.gov.tr/tahmin/il-ve-ilceler.aspx?m='.$this->il))))
return false;
return true;
}
public function get_icon_path($icon,$day) {
if (!$icon)
return false;
$local_folder = '/var/www/weather_images/';
$base_path = '/var/www/weather_images/';
$icon_name = $this->il.'_'.$day.'.gif';
if (($r_icon =
file_get_contents('http://www.mgm.gov.tr/FILES/imgIcon/99/e_36x36t_png/'.$icon)))
{
if (file_put_contents($local_folder.$icon_name, $r_icon)){
return $base_path.$icon_name;
}else{
return false;
}
}else {
return false;
}
}
public function get_current_weather() {
if (!$this->get_url())
return false;
try {
//echo $this->get_data;
$current_icon_exp = explode('id="divSonDurum"',
$this->get_data);
$current_icon_exp_2 = explode('</table>',
$current_icon_exp[1]);
$current_icon_exp_3 = explode('<img src="',
$current_icon_exp_2[0]);
$current_icon_exp_4 = explode('"', $current_icon_exp_3[1]);
$current_icon_exp_5 = explode('/', $current_icon_exp_4[0]);
$current_exp = explode('<em class="renkMax">',
$current_icon_exp_2[0]);
$current_exp_close = explode('°C</em>', $current_exp[1]);
$tomorrow_min_exp = explode('<td id="cp_sayfa_thmMin2"
class="arkaAlter minS">',$current_icon_exp[1]);
$tomorrow_min_exp_last = explode('</td>',
$tomorrow_min_exp[1]);
$tomorrow_max_exp = explode('<td id="cp_sayfa_thmMax2"
class="arkaAlter maxS">',$tomorrow_min_exp[1]);
$tomorrow_max_exp_last = explode('</td>',
$tomorrow_max_exp[1]);
$tomorrow_icon_exp = explode('<img
id="cp_sayfa_imgHadise2"', $tomorrow_max_exp[1]);
$tomorrow_icon_exp_2 = explode('src="', $tomorrow_icon_exp[1]);
$tomorrow_icon_exp_3 = explode('"', $tomorrow_icon_exp_2[1]);
$tomorrow_icon_exp_4 = explode('/', $tomorrow_icon_exp_3[0]);
$current = $current_exp_close[0] != '' ?
$current_exp_close[0] : 99;
$current_icon =
$current_icon_exp_5[count($current_icon_exp_5)-1];
$tomorrow_min = $tomorrow_min_exp_last[0] != '' ?
$tomorrow_min_exp_last[0] : 99;
$tomorrow_max = $tomorrow_max_exp_last[0] != '' ?
$tomorrow_max_exp_last[0] : 99;
$tomorrow_icon =
$tomorrow_icon_exp_4[count($tomorrow_icon_exp_4)-1];
$return_val = array();
$return_val['current_temp_c'] = round($current);
$return_val['current_icon'] = $current_icon;
$return_val['tomorrow_low_c'] = round($tomorrow_min);
$return_val['tomorrow_high_c'] =
round($tomorrow_max);
$return_val['tomorrow_icon'] = $tomorrow_icon;
return $return_val;
}catch (Exception $e){
$this->e = $e;
return false;
}
}
}
$iller =
array('ADANA','ADIYAMAN','AFYONKARAHISAR','AGRI','AKSARAY','AMASYA','ANKARA','ANTALYA','ARDAHAN','ARTVIN','AYDIN','BALIKESIR','BARTIN','BATMAN','BAYBURT','BILECIK','BINGOL','BITLIS','BOLU','BURDUR','BURSA','CANAKKALE','CANKIRI','CORUM','DENIZLI','DIYARBAKIR','DUZCE','EDIRNE','ELAZIG','ERZINCAN','ERZURUM','ESKISEHIR','GAZIANTEP','GIRESUN','GUMUSHANE','HAKKARI','HATAY','IGDIR','ISPARTA','ISTANBUL','IZMIR','K.MARAS','KARABUK','KARAMAN','KARS','KASTAMONU','KAYSERI','KIRIKKALE','KIRKLARELI','KIRSEHIR','KILIS','KOCAELI','KONYA','KUTAHYA','MALATYA','MANISA','MARDIN','MERSIN','MUGLA','MUS','NEVSEHIR','NIGDE','ORDU','OSMANIYE','RIZE','SAKARYA','SAMSUN','SIIRT','SINOP','SIVAS','SANLIURFA','SIRNAK','TEKIRDAG','TOKAT','TRABZON','TUNCELI','USAK','VAN','YALOVA','YOZGAT','ZONGULDAK');
//$iller = array('ANKARA');
$weather = new weather();
foreach ($iller as $il){
$weather->il = $il;
$response = $weather->get_current_weather();
if($response){
$sql_ext = '';
if ($response['current_temp_c'] != 99 ){
$sql_ext .= ",current_temp_c=$response[current_temp_c]";
}
if ($response['tomorrow_low_c'] != 99){
$sql_ext .= ",tomorrow_low_c=$response[tomorrow_low_c]";
}
if ($response['tomorrow_high_c'] != 99){
$sql_ext .= ",tomorrow_high_c=$response[tomorrow_high_c]";
}
if (strlen($response['current_icon']) > 1 &&
$response['current_icon'] != '0.png') {
$current_icon_path = $weather->get_icon_path(
$response['current_icon'], 'curr' );
if (strlen($current_icon_path) > 1)
$sql_ext .= ",current_icon='$current_icon_path'";
}
if (strlen($response['tomorrow_icon']) > 1 &&
$response['tomorrow_icon'] != '0.png') {
$tomorrow_icon_path = $weather->get_icon_path(
$response['tomorrow_icon'], 'tomorrow' );
if (strlen($tomorrow_icon_path) > 1)
$sql_ext .= ",tomorrow_icon='$tomorrow_icon_path'";
}
if (strlen($sql_ext) > 0){
$sql_ext = substr($sql_ext, 1);
}
}else{
//echo $weather->e."\n";
}
}
--
M.Atıf CEYLAN
Yurdum Yazılım
_______________________________________________
Linux-programlama mailing list
[email protected]
https://liste.linux.org.tr/mailman/listinfo/linux-programlama
Liste kurallari: http://liste.linux.org.tr/kurallar.php